Results 1 to 8 of 8
  1. #1
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Emerald Beach, New South Wales, Australia
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Disable macros in docs opened using VBA (Xp & 97)

    <P ID="edit" class=small>(Edited by jscher2000 on 15-Jul-04 21:21. Changed subject to something more descriptive.)</P>Hi

    when opening documents via automation I occasionally get one that has a dialog form that is opened. This kills me dead.

    The opening of a dialog in word can only be achieved by VBA? As such I though I'd just change the security level for word when creating the word application. Then I discovered that there is no programmatic access to the Macro Security level, makes sense when you think about it <img src=/S/crazy.gif border=0 alt=crazy width=15 height=15>.

    So now I'm wondering if there is any way to open a document and prevent macros running

    I'm doing something like this

    <pre>
    Set appWord = CreateObject("Word.Application")
    appWord.Visible = True
    appWord.WindowState = wdWindowStateMinimize
    End If

    With appWord
    .Documents.Open FileResults(fileNo, 1)
    </pre>



    can I prevent macros in the document that I am opening from running?

    Thanks

    Stewart

  2. #2
    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: Disable macros in docs opened using VBA (Xp &

    No, there definitely is no programmatic access to the Macro Security setting. I'm not even sure you can set it by writing to the Registry (it might be buried in the DataSettings key, which is indecipherable to humans).

    You could try using SendKeys to send Alt+D. If the dialog is there, this will disable the macros, and if it isn't, probably nothing will happen. Getting the timing right might be difficult though, so you could consider a third party solution. Someone once posted a link to Buzof from Basta Computing, a shareware program that can be trained to recognize and dismiss various dialogs. If it works, it may well be worth the $15 to you.

    One other thought: if you start Word using the /a switch, it disables the macros in the Normal template and other global templates. Maybe if you open a document with the /a switch it also will disable document and attached template macros? (I'd experiment but it's getting late...) Harder to grab control of the application, though, when started from the shell.

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Disable macros in docs opened using VBA (Xp & 97)

    If you have a look back through the archives here you will find an old Wordbasic command which will turn off/on automacros.

    This post by HansV contains what you need <post#=339777>post 339777</post#>
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Emerald Beach, New South Wales, Australia
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Disable macros in docs opened using VBA (Xp & 97)

    Andrew,

    how on earth did you find that. Yet another bit of Hans magic, delivered by Andrew magic.

    I had searched through the lounge but I would have never found that by myself in a million years.

    using the code

    Set appWord = CreateObject("Word.Application")
    appWord.WordBasic.DisableAutoMacros 1

    solved my problem perfectly.

    once again Thank You.

  5. #5
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Emerald Beach, New South Wales, Australia
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Disable macros in docs opened using VBA (Xp &

    I appreciate you taking the time to reply.

    I tried the alt-D approach with no success (after your suggestion) and was trying very hard to figure out what my next step was.

    The trainable dialog closer isn't any good to me as I do not know what dialog will appear, or even if one will.

    Andrew Lockton somehow managed to dig up a solution from an obscure part of the lounge so I'm ok now.

    Thanks.

    Stewart

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Disable macros in docs opened using VBA (Xp & 97)

    Stewart

    Don't forget to turn the automacros back on at the end of your macro by using the second line. This will avoid dramas next time you DO want the automacros to fire.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  7. #7
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Emerald Beach, New South Wales, Australia
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Disable macros in docs opened using VBA (Xp & 97)

    Andrew,

    It's the second thing I did. Interestingly enough turning the macros back on didn't work for me under XP.

    I can only assume that this relates to the effected security level.

    the appWord.WordBasic.DisableAutoMacros 1
    set the Macro Security Level to high.
    The appWord.WordBasic.DisableAutoMacros 0
    had no effect. Obviously we are not meant to be able to reduce security levels via code, again to prevent macro viruses I can understand this.

    I can also live with manually resetting the Macro security level after I have completed processing.

    Again, thanks for the help.

    regards

    Stewart


    Don't forget to turn the automacros back on at the end of your macro by using the second line. This will avoid dramas next time you DO want the automacros to fire.

  8. #8
    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: Disable macros in docs opened using VBA (Xp &

    My mistake, I assumed that you were trying to dismiss the Disable/Enable macros dialog, which should appear if "Medium" security it set and there are macros (auto or not) in the document. But if you only have Auto macros to worry about, it sounds as though you've got it covered.

Posting Permissions

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