DocumentBeforePrint event

H

Helen Trim

Is there a way to see how many copies were requested in the
DocumentBeforePrint event? I store documents in a database and I need to
store how many copies are needed and how many have already been printed.

Thanks,
Helen
 
O

old man

Hi,

This will work (based on code from a recent answer from Jay Friedman in this
forum):

dim intSaveNumCopies as integer ' will contain numbr of copies printed

Dim dlgPrint As Dialog
Set dlgPrint = Dialogs(wdDialogFilePrint)
With dlgPrint
.Display
' you can check if the user wants to print... lets assume they do

ActiveDocument.PrintOut _
Background:=True, _
Range:=.Range, _
from:=.from, to:=.to, _
Item:=wdPrintDocumentWithMarkup, _
Copies:=.numcopies, _
Pages:=.Pages
intSaveNumCopies = dlgPrint.numcopies
End With

To understand how to set word applications event please read:
http://word.mvps.org/faqs/macrosvba/AppClassEvents.htm
and
http://msdn2.microsoft.com/en-us/library/aa140279(office.10).aspx

I created a routine in the template:
Private Sub AppThatLooksInsideThisEventHandler_DocumentBeforePrint(ByVal Doc
As Document, Cancel As Boolean)
MsgBox "in app event before print app event"
End Sub

I created a subroutine with the following code in the word document:
Sub fileprint()
MsgBox "fp"
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

When I opened the document and attached the template with app event this is
the order of what I saw:

1) A msgbox that said "FP"
2) a msgbox that said "in app event before print app event" 'app event
3) The document printed

So intercepting the event won't help because it occurs before the print
(application.printout)

old man
 

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