Results 1 to 6 of 6

Message box when no file is active

Threaded View

  1. #1
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,177

    Message box when no file is active

    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.

    Run-time error '91':
    Object variable or with block variable not set
    Which high-lites the MsgBox portion of code depicting it as failed.
    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
    Edit:
    Remove Color codes
    Last edited by Rick_Stanich; 12-01-2010 at 04:02 PM.
    Regards

    Rick
    Win10, Office 365

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1