Trouble finding problem with code.

RLPeloquin

Board Regular
Joined
Jul 4, 2020
Messages
73
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: 7

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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?
 
Upvote 0
Solution
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!!
 
Upvote 0

Forum statistics

Threads
1,214,829
Messages
6,121,826
Members
449,051
Latest member
excelquestion515

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
Back
Top