1

i have a vba macro that will print a letter twice with different page settings. This works great. But sometimes (i dont know why) the printing dialog (select printer, ...) appear. How can i hide the printing dialog. I like to print on the default printer and dont like to change the settings.

Somebody an idea

ActiveDocument.PrintOut Background:=true

Dont have any effect.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Maik
  • 11
  • 2

1 Answers1

0

Word lets you control the DocumentBeforePrint event, which in turn gives one access to controlling the display of the print dialog box. This event needs to be manually added to your VBA code. Whether you control the dialog for a single document or all future documents will depend on if the code is placed within a single document or the template that generates new documents.

Add this code to the VBA Declarations section for ThisDocument:

 Option Explicit
 Private WithEvents app As Application

Then edit the Document_New() and Document_Open() subs to include this line:

 Set app = Application

Finally, create the DocumentBeforePrint sub (again in ThisDocument) with the following code:

 Private Sub app_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)

 'Invoke your macro to print a letter twice with different settings here

 Cancel = True

 End Sub

The Cancel = True line cancels the standard Print dialog box, so that the code does not try to print the document twice. This solution runs on the premise that your existing macro prints a document without accessing the print function via a method such as Dialogs(wdDialogFilePrint).Show, which would display the print dialog box. Hope this helps.

joeschwa
  • 3,083
  • 1
  • 21
  • 41