Trouble finding problem with code.

RLPeloquin

Board Regular
Joined
Jul 4, 2020
Messages
61
Office Version
  1. 2019
Platform
  1. Windows
It seems when I close my Workbook from any other page other than the Home page I get this error. Any suggestions, Thanks in advance!
Private Sub Workbook_Open()

Application.WindowState = xlMaximized

Worksheets("Home").Activate

UserForm1.Show



End Sub



Private Sub Workbook_SheetActivate(ByVal Sh As Object)

On Error Resume Next



Select Case ActiveSheet.Name

Case "Home"

UserForm1.Show modeless

Case Else

UserForm1.Hide

End Select



If Sh.Name = "Site 1" Then

Call If_And_Elseif

'Call Auto_Fit



ElseIf Sh.Name = "Site 2" Then

Call If_And_Elseif

'Call Auto_Fit



ElseIf Sh.Name = "Site 3" Then

Call If_And_Elseif

'Call Auto_Fit

End If

End Sub
 

Attachments

  • Sample Error.jpg
    Sample Error.jpg
    185.4 KB · Views: 5

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

vw412

Active Member
Joined
Dec 16, 2011
Messages
343
Office Version
  1. 2019
  2. 2016
  3. 2010
  4. 2007
Platform
  1. Windows
Not able to duplicate the error but you do have some coding problems.

In the Workbook_Open proc you show the Userform1 as Modal but in the Workbook_SheetActivate you show it as "modeless". Is that your intention? The Userform1.Show in Workbook_Open forces a user to dismiss ("X" out) the Userform before they can interact with the workbook.

In the Workbook_SheetActivate proc,
VBA Code:
Userform1.Show modeless
should be
VBA Code:
Userform1.Show vbModeless

Why not combine the Select/Case and If/ElseIf blocks into one Select/Case?
 
Solution

RLPeloquin

Board Regular
Joined
Jul 4, 2020
Messages
61
Office Version
  1. 2019
Platform
  1. Windows
Not able to duplicate the error but you do have some coding problems.

In the Workbook_Open proc you show the Userform1 as Modal but in the Workbook_SheetActivate you show it as "modeless". Is that your intention? The Userform1.Show in Workbook_Open forces a user to dismiss ("X" out) the Userform before they can interact with the workbook.

In the Workbook_SheetActivate proc,
VBA Code:
Userform1.Show modeless
should be
VBA Code:
Userform1.Show vbModeless

Why not combine the Select/Case and If/ElseIf blocks into one Select/Case?
Thanks, this seems to work! you're the best!!
 

Forum statistics

Threads
1,143,835
Messages
5,721,067
Members
422,339
Latest member
SHIVATVM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top