Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Halting Document_Open macros (Word XP)

    Hi, all.
    I have a challenge at work: I was requested to create a process that will automatically strip any Document_Open code from a document. (The reason for this is that the documents are input for an automated process, and we need to ensure that no code runs when this process opens the document unattended.)
    But my question is: how can I open a document through code (as part of a "preflight" process) but prevent any code that may be attached to it from running? I have already written code that will strip any modules from a document, but that assumes the document is already open. Is there a VBA equivalent to holding down the Shift key while a document opens? Or is there a method that can tell if code is attached to a document even before I even open it?
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Halting Document_Open macros (Word XP)

    WordBasic to the rescue! The old WordBasic instruction DisableAutoMacros can be used to prevent automatic macros, including Document_Open, from running.

    WordBasic.DisableAutoMacros 1
    Set myDoc = Documents.Open("MyDocument.doc")
    WordBasic.DisableAutoMacros 0

  3. #3
    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: Halting Document_Open macros (Word XP)

    Hans' solution makes much more sense than the alternative that came to my mind: the /m startup switch should suppress macros from running when opening a document, and if your application were to "shell" the documents open, you could use /m as part of your command line.

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

    Re: Halting Document_Open macros (Word XP)

    has anybody ever seen any justification from msft for not having an equivalent of disableautomacros?

  5. #5
    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: Halting Document_Open macros (Word XP)

    Of course not. But you should infiltrate one of those live internet chat things MS has now and then and demand an answer. <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

Posting Permissions

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