VBA Macro command to allow print routine

C

Colin Hayes

Hi

I'm printing via a macro , and keep getting a popup from word saying

' The margins for section 1 are set outside the printable area of the
page. Do you want to continue?'

As the answer to this will always be Yes , does anyone know of a command
I can put in my macro to allow the print to go ahead without having to
always stop for the popup?


Grateful for any advice.


Best Wishes


Colin
 
L

Lene Fredborg

You can turn off alerts as shown in the example below. If you use the Print
dialog box, your code could be:

Application.DisplayAlerts = wdAlertsNone

Dialogs(wdDialogFilePrint).Show

Application.DisplayAlerts = wdAlertsAll


NOTE that the code line “Application.DisplayAlerts = wdAlertsNoneâ€
suppresses not only the margins settings warning but all other types of
warnings too. Since Word does not automatically set DisplayAlerts back, the
last line is used to set DisplayAlerts back to show all alerts again.

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
C

Colin Hayes

Lene said:
You can turn off alerts as shown in the example below. If you use the Print
dialog box, your code could be:

Application.DisplayAlerts = wdAlertsNone

Dialogs(wdDialogFilePrint).Show

Application.DisplayAlerts = wdAlertsAll


NOTE that the code line “Application.DisplayAlerts = wdAlertsNoneâ€
suppresses not only the margins settings warning but all other types of
warnings too. Since Word does not automatically set DisplayAlerts back, the
last line is used to set DisplayAlerts back to show all alerts again.

HI

OK Thanks for getting back.

Couldn't quite get it working. I just need to suppress the popup , and
wasn't sure where to insert the switch off / switch back on code to my
macro. I tried it various places , but the popup persisted. Perhaps you
could advise.

Here's my macro :

' Print_Two_Copies Macro

Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=2, Pages:="", PageType:=wdPrintAllPages,
_
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:=
_
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0


End Sub


It just print two copies of the open document.



Best Wishes


Colin
 
L

Lene Fredborg

In relation to your macro, you will need to disable background printing in
order for it to work. Below, you will find a revised version of your code
(note that “Background:=True†in your original code has been changed to
“Background:=Falseâ€):


Dim bBackgroundPrint As Boolean

'Save current setting for background printing
bBackgroundPrint = Options.PrintBackground

Application.DisplayAlerts = wdAlertsNone

Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=2, Pages:="", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=False, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0

Application.DisplayAlerts = wdAlertsAll

'Restore setting for background printing
Options.PrintBackground = bBackgroundPrint

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
C

Colin Hayes

Lene said:
In relation to your macro, you will need to disable background printing in
order for it to work. Below, you will find a revised version of your code
(note that “Background:=True†in your original code has been changed to
“Background:=Falseâ€):


Dim bBackgroundPrint As Boolean

'Save current setting for background printing
bBackgroundPrint = Options.PrintBackground

Application.DisplayAlerts = wdAlertsNone

Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=2, Pages:="", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=False, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0

Application.DisplayAlerts = wdAlertsAll

'Restore setting for background printing
Options.PrintBackground = bBackgroundPrint

Hi Lene

OK that's got it - it's working perfectly now.

Thanks for your time and expertise - I'm very grateful.



Best Wishes


Colin
 

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