• Prevent Word Autoexec Macros from running when opened from Access

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Prevent Word Autoexec Macros from running when opened from Access

    Author
    Topic
    #481288

    Not sure if this should be on Access OR Word but …..

    I have an access database that opens a word document.
    I can open the document no problem

    BUT…. The word document has an Auto_Open Macro (old school) in it that
    is required to run if the document is opened manually.
    This invoked a user form that waits for input.

    BUT when opened from Access by Ole Automation I do not want this to run.
    I could possibly bypass this with shell, but it needs to open as a Word Object from Access.

    So any ideas??

    Is there something I could do when opening it to stop word from running the macro
    Or Can I open it and force another macro to run first

    Or is there something I can add to Word Document, that will help it determine
    that it was called from VBA (without putting it into a template).

    If that is all a bit vague I will expand upon the detail

    BUT the gist of it is this

    Word Document is opened from explorer then Macro (in Word Doc) MUST RUN.
    Word is opened as Ole Object from Access then Word macro MUST NOT RUN. :huh:

    Viewing 0 reply threads
    Author
    Replies
    • #1316702

      OK, in answer to my own question, this appears to work

      Code:
      oW.WordBasic.DisableAutoMacros 1
      

      If I run that bit of OLD Code against the Word Object, before I open the document, then it is OK.

      Then after that is opened I turn it back on again with

      Code:
      oW.WordBasic.DisableAutoMacros 0
      

      If anyone has a more elegant and up to date solution I would love to know! :huh::rolleyes:

    Viewing 0 reply threads
    Reply To: Prevent Word Autoexec Macros from running when opened from Access

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

    Your information: