Word2003: Inhibit execution of Private Sub Document_Open

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Word2003: Inhibit execution of Private Sub Document_Open

Post by ChrisGreaves »

Code: Select all

Private Sub Document_Open()
'    Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
'        wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
'        Collate:=True, Background:=False, PrintToFile:=False, PrintZoomColumn:=0, _
'         PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
    Call Print_ShowNoWarning_1
    Application.Quit
End Sub

Sub Print_ShowNoWarning_1()
'    Macro 1- prints the active document without showing the Print dialog box:
    With Application
        'Turn off DisplayAlerts
        .DisplayAlerts = wdAlertsNone
        'Print document
        'Background print must be turned off to prevent message
        .PrintOut Background:=False
        'Turn on DisplayAlerts again
        .DisplayAlerts = wdAlertsAll
    End With
    ThisDocument.Saved = True
End Sub
How can I disable auto-execution when opening a document with VBA?
Yes, I have shot myself in the foot again!
The document in question works well in that on being opened, it issues a call to print itself and then quits the application. In retrospect, quitting the Word application was not a good idea.

I am today processing documents on my hard drive and my application crashes during a document because the document issues an "Application.Quit" as the seventh line of the document's "Private Sub Document_Open()".

For now I have bypassed this file, but I cannot remember how to suppress auto-execution when opening a document from VBA in Word.

I must have done this in the past, because it seems that I have spent my life processing documents!

Any help would be appreciated.
Thanks
Chris
An expensive day out: Wallet and Grimace

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word2003: Inhibit execution of Private Sub Document_Open

Post by HansV »

To disable running automatic macros, issue

Code: Select all

WordBasic.DisableAutoMacros 1
before opening documents, and

Code: Select all

WordBasic.DisableAutoMacros 0
afterwards.

:whisper: Yes, WordBasic still works, even in the latest version of Word, and sometimes it's the only way to get things done...
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Word2003: Inhibit execution of Private Sub Document_Open

Post by ChrisGreaves »

HansV wrote:
23 Apr 2021, 09:53

Code: Select all

WordBasic.DisableAutoMacros 1
Untitled.png
Thank you, Hans.
Now that I know what I'm looking for, I can search for and find it in my own code. :scratch:
It's not as if I didn't know about it.
It's all Kevin Stroud's fault, because I was listening to his episode on Prefixes this week, and "inhibit" took precedence over "disable" in my brain!
Thanks again :thankyou:
Chris
You do not have the required permissions to view the files attached to this post.
An expensive day out: Wallet and Grimace