Run-time error '91' Help

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
563
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I'm not sure what I am doing wrong here. Sometimes when I open my worbook, I will get a Run-time error '91': Object variable or With block variable not set and sometimes I won't get it. That makes no sense but when I added the Option Explicit to the top of the code I get the error message every time.
When I step through the code, the error occurs after
Code:
ActiveWindow.Visible = False
Full Code below:
Code:
Option Explicit
Private Sub Workbook_Open()
    
    Dim result As String
    
    ActiveWindow.Visible = False


    result = MsgBox("Do you want to open the product list worksheet prior to opening the userform?", vbYesNo + vbDefaultButton2, "Select Option")
        
    If result = vbYes Then
        Windows("Happy.xlsm").Visible = True
    Else
        selectFilefrm.Show
    End If
End Sub
I'm also not sure if result should be a string and not something else.
Code:
Dim result As String

Thank You
 
Last edited:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
You don't need Result, try
Code:
Private Sub Workbook_Open()
    
    
    ActiveWindow.Visible = False


    If MsgBox("Do you want to open the product list worksheet prior to opening the userform?", vbYesNo + vbDefaultButton2, "Select Option") = vbYes Then
        Windows("Happy.xlsm").Visible = True
    Else
        selectFilefrm.Show
    End If
End Sub
 
Upvote 0
I'm still getting the same error message with the above code at the same place. Now my message box doesn't even appear. Thank you for your help.
 
Upvote 0
What line is highlighted when you click debug?
 
Upvote 0
Does it take long for that workbook to open?
 
Upvote 0
In that case I'm not sure why you are getting the error.
 
Upvote 0
If you get an error on this line
Code:
ActiveWindow.Visible = False
The code never gets to the message box
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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