Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Star Lounger
    Join Date
    Jun 2002
    Location
    Seymour, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA Macro (Windows 98)

    Is there a way to code a macro so that a message box will appear when a word document is loading or
    after it has loaded? If so how do I do this?

    Thanks in advance

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: VBA Macro (Windows 98)

    If you want this to apply to all documents based on any template then you probably want an application level event handler.

    Guy Gallo just posted an example of one of these in <!post= Post #153405, 153405> Post #153405<!/post>

    StuartR

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Macro (Windows 98)

    Use an AutoOpen macro in the Normal template,

  4. #4
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Macro (Windows 98)

    Or use a
    <pre>Private Sub Document_Open()
    MsgBox "Hello Document_Open!"
    End Sub</pre>

    in the "ThisDocument" class module of the attached template.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Macro (Windows 98)

    Document macros should be used as a last resort.

  6. #6
    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: VBA Macro (Windows 98)

    AutoOpen is simpler to code than an App_DocumentOpen(). Is one better than the other?

    Does holding down the Shift key bypass an event handler, as it does with an Auto macro?

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Macro (Windows 98)

    IMHO

    Auto macros should be used when they are global, or apply to all documents based on a template.

    Document macros should be used only when specific to a document or provide some event functionality that cannot be provided by an Auto macro.

    Auto macros are easier to maintain as one need maintain only 1 copy per template. Document macros could be in documents scattered all over the drives.

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

    Re: VBA Macro (Windows 98)

    This explanation doesn't at all jibe with my understanding of 'Document macros' i.e. Document_New, etc. - the main use for these is not intended to be in relation to individual documents as your comments appear to imply. Rather, they get used in the same situations that 'Auto' macros get used, namely, in attached templates from which documents get created.

    So just like Auto macros, Document macros are used "one copy to a template". There are some subtle distinctions between Auto and Document macros (such as the order in which they fire), but one practical distinction is that an Auto macro will appear in the macros list, while a Document macro will not - definitely a benefit.

    Also not sure about the statement that Auto macros should be used when they are global - AutoExec and AutoExit are Auto macros that can be used in a global template, but AutoOpen and AutoClose won't fire in a global template, unless the document being opened or closed happens to be based on that global template (which itself is something you would likely never want to do).

    Gary

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

    Re: VBA Macro (Windows 98)

    Holding down the Shift key does appear to bypass the event handler, same as an Auto macro.

    The difference in when to use AutoOpen (or Document_Open) vs. when to use App_DocumentOpen() comes down to this: AutoOpen (or Document_Open) is only going to fire when a document is opened which is based on the template in which the AutoOpen or Document_Open procedure is housed - so it's template-specific.

    (One possible exception: possibly an AutoOpen may run globally if it's placed in Normal.dot, but I've never tested it. But since in practice it's best to leave procedures like these out of Normal.dot, it may not be relevant.)

    If you need to ensure that code runs upon the open of every document, no matter which template it's based on, then you need an application level document open event handler, in a global template.

    Gary

  10. #10
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Macro (Windows 98)

    > Document macros should be used as a last resort.

    I heard it the other way round:
    Auto macros are an old legacy that the Word developpers would like to get rid off ASAP, and document event handlers are the encouraged method.

    Though I heard this second hand from an MSMVP, not from the horse's mouth...

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

  11. #11
    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: VBA Macro (Windows 98)

    Okay, but here is the distinction that I was trying to get at: there is an application-level event named DocumentOpen which would seem to trigger in the same situations as a global AutoOpen, although I haven't tried it (Gary's message suggests that he tried it).

    Auto macros are very easy to write, while event handlers are a hassle to code and instantiate. On the other hand, Auto macros seem to be something of a legacy that will eventually die away. From your experience on the more technical end, though, if you have the choice between creating a global AutoOpen macro and a global DocumentOpen application event handler, which is preferable?

  12. #12
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Macro (Windows 98)

    I was talking about document macros, i.e., critters included in THE document.

    Me, Myself, and I have no objection to macros in ThisDocument in the template itself.

  13. #13
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Macro (Windows 98)

    Auto macros in Normal do run globally.

  14. #14
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    New York
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Macro (Windows 98)

    Just to weigh in on this debate.

    I would only code in the document object IN A TEMPLATE -- like the globat event handler example sited above -- and preferably only in a Global Add-in, not a template to be used to generate documents. Don't see any advantage.

    As for coding directly into a document. Why? I'm not sure what the benefit is over coding in templates upon which documents are based. It seemed when this was introduced with VBA it only further clouded the template paradigm. Now folks can saved recorded macros (the first step for mosts people in automating their systesm) in Normal.dot, template, AND document. I'm sure this just confuses the new user.

    INMHO, everything should be done to encourage users to undrestand the relation between a doc and it's underlying template. Global Add-ins -- fine, let them exist as special cases of Normal.dot -- out of harms way as the user can't add to them.

    If there's an advantage to coding Open New events in the Document object of a template rather than as AutoOpen et all, I don't see it. And if the document object is NOT bypassed by holding shift key then there's a compelling reason NOT to use the Doc Object.

  15. #15
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    New York
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Macro (Windows 98)

    Do you want a message box, which the user will have to cancel? Or a splash screen that will vanish after a specific time?

    For every document opened? Or for a class of documents based on a specific template?

Page 1 of 2 12 LastLast

Posting Permissions

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