How do you show a message box (MsgBox) when no excel file is opened but Excel is running.
Sometimes I have Excel open but no workbook, I have a couple macros that inform the user that a specific type file is required to run the given macro.
I am using a tool bar with drop downs for users to select a macro and I just stumbled on this, if I dont have a workbook open the macro that is a message will fail.
Which high-lites the MsgBox portion of code depicting it as failed.Run-time error '91':
Object variable or with block variable not set
Edit:![]()
Option Explicit Sub Start() On Error GoTo EndIt If Left(ActiveWorkbook.Name, 6) = "AS9102" Then GmMotDataCollectorForm.Show Else EndIt: MsgBox "You must have an active AS9102 excel file open." & _ vbCrLf & _ "Example name: ""AS9102 4502730B Y 135-1 100710.xls""" & _ vbCrLf & _ "Current file name: " & ActiveWorkbook.Name End If End Sub
Remove Color codes
Bookmarks