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:
Just curious, but let's say it did take a long time to load then what would be your suggestion? Thank you.
 
Last edited:
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
You could use Application.Wait to build in a delay, before the code runs. Allowing the workbook to fully open first.
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,357
Members
449,155
Latest member
ravioli44

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