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

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Disable macros in docs opened using VBA (Xp & 97)

    Author
    Topic
    #407406

    (Edited by jscher2000 on 15-Jul-04 21:21. Changed subject to something more descriptive.)

    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 crazy.

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

    I’m doing something like this

       
            Set appWord = CreateObject("Word.Application")
            appWord.Visible = True
            appWord.WindowState = wdWindowStateMinimize
        End If
    
            With appWord
                .Documents.Open FileResults(fileNo, 1)
    

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

    Thanks

    Stewart

    Viewing 3 reply threads
    Author
    Replies
    • #851961

      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.

      • #851975

        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

        • #851985

          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.

        • #851986

          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.

      • #851976

        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

    • #851962

      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.

    • #851971

      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

      • #851973

        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.

        • #851977

          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.

          • #851979

            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.

          • #851980

            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.

        • #851978

          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.

      • #851974

        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.

    • #851972

      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

    Viewing 3 reply threads
    Reply To: Disable macros in docs opened using VBA (Xp & 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: