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