Results 1 to 2 of 2
  1. #1
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Prevent Word Autoexec Macros from running when opened from Access

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

  2. #2
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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!
    Andrew

Posting Permissions

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