Results 1 to 6 of 6
  1. #1
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: MsgBox fails when no document active?

    This code -

    Public Sub cmd_WhoAmI()
    MsgBox "Hello"
    End Sub

    - runs fine in Word2000 with no document open. I placed it in Normal.dot and used Alt+F8 to run it.

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MsgBox fails when no document active?

    Here's how I do that little question-mark thing, left-hand end of every application toolbar. I call it the WhoAmI? thing.

    It seems to me that in Word97SR2 the MsgBox command fails if there is no document open. I discovered this by accident tonight. I have the appliaction in the Startup directory, and just for once decided to close the blank document (I'd just loaded Word) before testing the application from go to whoa.

    In theory a simple sub:

    Public Sub cmd_WhoAmI()
    MsgBox "Hello"
    End Sub
    should be enough to demonstrate this.

    I'd like to hear from you if

    1) You run Word97SR2 and MsgBox fails when no document is open and
    2) What happens in Word2000.




    <pre>Public Sub cmd_WhoAmI()
    MsgBox strWhoAmI
    End Sub


    Public Function strWhoAmI()
    strWhoAmI = "Application: """ & strcApplication & """ & _
    Template: """ & MacroContainer.Name & """ Build: " & intGetBuildSequence
    End Function


    Public Function intGetBuildSequence() As Integer
    ' Procedure : IncrementBuildSequence
    ' Description: Increments a unique sequence number in the current document.
    ' Copyright: Chris Greaves Inc.
    ' Inputs: None.
    ' Returns: None.
    ' Assumes: None.
    ' Side Effects: None.
    ' Tested: By saving the current document.
    ' Method:
    ' Obtain the next available value of an internal sequence,
    Dim lngIndex As Long
    lngIndex = lngIndexCustomDocumentProperties(ActiveDocument.Na me, strcIdentifier)
    If lngIndex < 0 Then
    lngIndex = lngAddCustomDocumentProperties(ActiveDocument.Name , strcIdentifier)
    Else
    End If
    intGetBuildSequence = Val(ActiveDocument.CustomDocumentProperties(lngInd ex))
    End Function

    </pre>



    *** Edited Geoff W Split long lines in "pre" tags ***

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox fails when no document active?

    Thanks. I figured it had to be some sort of oversight on the part of the programmer at MSoft.

    After all, if you DID have an application macro that depended on a document, how could you convey to the user that they had to do soemtjhing, other than by an elementary MsgBox. (sniff!)

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: MsgBox fails when no document active?

    Chris,

    The MsgBox function runs fine with no documents open, in both Word 97 and Word 2K - so some other mystery must be in play....

    Gary

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox fails when no document active?

    Chris, (see Gary's post first)

    I suspect you have an AutoExit or something with a statement that starts with

    Activedocument.

    that executes before your little msgbox.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox fails when no document active?

    Thanks guys; you're right. I *can* get it to work under certain circumstances. I'll track down what inhibits it next time it happens.

Posting Permissions

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