Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Word: Determining number of pages printed

Status
Not open for further replies.

markymids

Technical User
Aug 31, 2007
2
GB
Hi,

Basically I would like to use VBA to determine the number of pages that were printed. Ie if one page of a document was printed only I would like to perform a different function than if the whole document was printed.

Is this possible?

To explain further I have a button on a toolbar to print one page only (ActiveDocument.PrintOut Range:=wdPrintCurrentPage) if this button is pressed I want to turn off printing comments.. I know I could do this by the following code:

Options.PrintComments = False

However there is an event handler that is called before printing which turns comments back on!!

Private Sub oApp_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
Options.PrintComments = True
End Sub

So even if I turned the comments off in the code for my toolbar button, they would still turn on again!

I'm sure there is a simple way to do this but I'm tearing my hair out here.

Thanks for any help anyone can give me!
 
Just have your one page button set a variable flag identifying that it has been clicked, then test the value of the variable in the before print event handler and turn print comments on or off as appropriate.
 
Thanks for the reply, I did think of doing that but the one page button is in a different template to the event handler (both templates are loaded at the same time).

Would I be able to check the state of a variable even if it is in another template?
 
I think it will work as long as the variable is declared as STATIC.

I'm sure someone with a better understanding of the life of variables will chime in.

If not, certainly a document variable would work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top