Prevent Word macro from running on open
Posted on 2005-05-11
Background: I have a program which takes user responses from an email, creates a main client folder and appropriate sub-folders...then opens the appropriate Word template and populates/saves to appropriate sub-folder...way cool, so far so good...
Dilema: Client askled last PM if I can create a utility off the UserForm to view the 4 classes of .doc in question...created a UserForm with 4 list boxes...they get populated correctly and when I click "Retrieve" button, lo and behold, there's the document...KINDA SORTA...what's happening is the document fields are getting updated with the current respondents answers rather than just giving me the .doc on file...obviously it's triggering the onOpen macro in Word...if I go to Windows Explorer and click the .doc in question, it opens with the "enable macros?" dialogue box...answer no and the .doc appears as I wanted...
Can I either vba "turn off" the macro on open or at the very lest get the dialogue box to open so the user can say No? I found a reference to the following line of code:
'WordBasic.DisableAutoMacros 1 'Disables auto macros
...when I run this I get "the remote server machine does not exist or is unavailable"...too bad, sounded like what I needed!
Code to open the Word doc is as follows:
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
On Error GoTo 0
Set wdDoc = wdApp.Documents.Open("" & ClientSelect & "\" & fullname & "IA.doc")
wdApp.Visible = True