How to suppress macro

J

Jeffery B Paarsa

After displaying Userform and extracting necessary fields from the user thru
Userform by double clicking on a templete X.dot following are the VBA code
that will be executed:

Private Sub CMDPrint_Click()
' some codes.....
With ActiveDocument
.Unprotect
ActiveDocument.Fields.Update
.Protect wdAllowOnlyFormFields
NPPkg.Hide
' .PrintOut
End With
openMedHistory ' This will open a new document using a new template...
see next few lines.
End Sub

Sub openMedHistory()
Word.Documents.Add Template:="G:\ZZZdoc\(ALL)MRPMedHist.dot", Visible:=False
With ActiveDocument
.Unprotect
.Bookmarks("PFName").Range _
.InsertBefore PFName
.Bookmarks("PFName").Range.Font.Color = wdColorRed
.Bookmarks("PLName").Range _
.InsertBefore PLName
.Bookmarks("PLName").Range.Font.Color = wdColorRed
ActiveDocument.Fields.Update
.Protect wdAllowOnlyFormFields
' .PrintOut
End With
End Sub
--

When I execute "openMedHistory" and the line
Word.Documents.Add Template:="G:\ZZZdoc\(ALL)MRPMedHist.dot", Visible:=False
will be executed it displays the UserForms for this newly added document.
How can I suppress this macro for the newly added Documents from being
invoked/executed? Or basically I don't want the the UserForm for this newly
added document to be displayed. Anybody can help how can I suppress this
macro?
Jeff B Paarsa
 
C

Cindy M.

Hi =?Utf-8?B?SmVmZmVyeSBCIFBhYXJzYQ==?=,
When I execute "openMedHistory" and the line
Word.Documents.Add Template:="G:\ZZZdoc\(ALL)MRPMedHist.dot", Visible:=False
will be executed it displays the UserForms for this newly added document.
How can I suppress this macro for the newly added Documents from being
invoked/executed? Or basically I don't want the the UserForm for this newly
added document to be displayed. Anybody can help how can I suppress this
macro?
Do any other macros in this document+template combination have to be available
for execution? Which version of Word?

You can use WordBasic.DisableAutoMacros -1 to turn off execution of Auto macros.
But you do have to remember to set it again to 0 to allow them to execute.

If NO macros need to execute you can set the AutomationSecurity to not allow
macros at all (Word 2002/2003).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
J

Jeffery B Paarsa

Hi Cindy,

I am running Word 2003. I used WordBasic.DisableAutoMacros -1 statement
right before I do Word.Documents.Add.... but I get the following:
Run-time error '438'
Object doesn’t support this property or method.
I downloaded the WordBasic and put it inside of the Office11 folder but
still the same.
 
J

Jeffery B Paarsa

Sorry I forgot to answer "Do any other macros in this document+template
combination have to be available for execution?"

Answer is No.
 
C

Cindy M.

Hi =?Utf-8?B?SmVmZmVyeSBCIFBhYXJzYQ==?=,
I am running Word 2003. I used WordBasic.DisableAutoMacros -1 statement
right before I do Word.Documents.Add.... but I get the following:
Run-time error '438'
Object doesn’t support this property or method.
Ah, my mistake. It's a 1, not -1. See

http://word.mvps.org/faqs/macrosvba/WordBasicCommands.htm

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top