Run-Time Error 91 - Object variable or With block variable not set

K1600

Board Regular
Joined
Oct 20, 2017
Messages
70
I've got a file that when it opens it does a Application.Visible = False and then loads my Login UserForm allowing the user to login.

Once the user has logged in the login UserForm hides rather than unloads as the other UserForms pick information from it during the rest of the process. I am having an issue that once I have run a report using coding Application.Visible = True is added to allow the user to then see the data that has been obtained from the report however when after excel is visible again the login UserForm is re-appearing on the screen. If I add a line of code to unload it then I get the above Run-Time Error. If I DeBug it, it takes me to the line with UsrFrmAdminLogin.Show vbModal.

I can also replicate the error by clicking the red 'X' on the Login UserForm before logging in, which leads me to think that the issue is with this rather then somewhere else in my code.

The code I am using on the workbook opening is below. Could this be something to do with me not being able to pre-approve the macro's and as such having to choose "Enable" once the document opens?

Thanks in advance for any help.

VBA Code:
Private Sub Workbook_Open()
    

'Hide excel after launch so only userform displays
    Application.Visible = False             'Add this to hide excel when UserForm loads

'Checks if outlook is open
Dim oOutlook As Object

    On Error Resume Next
    Set oOutlook = GetObject(, "Outlook.Application")
    On Error GoTo 0

    If oOutlook Is Nothing Then
        MsgBox "Please open Microsoft Outlook (e-mail application)." & vbCr & _
            "      You will need this open to use this system", vbExclamation
    End If

'Loads UserForm immediatly on file being opened
    UsrFrmAdminLogin.Show vbModal


End Sub
 

K1600

Board Regular
Joined
Oct 20, 2017
Messages
70
No. If it greys out, that means that the project compiled without any compile errors. That's good news! :)

No problems are apparent to me from what you have disclosed. Please post all of your code or provide a link , if possible, so that I can take a look at your workbook.
Well that's one good thing at least :)

The whole thing is across three workbooks with links in the code to each so sharing it isn't simple. Additionally, there are a lot of references to the my employer in the code which I would have to sanitise a lot of before I could post it which could likely defeat the object of posting it. However, that's very much for the offer and for your help.
 

Some videos you may like

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Watch MrExcel Video

Forum statistics

Threads
1,114,326
Messages
5,547,268
Members
410,783
Latest member
sonnny
Top