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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel AfterPrint Event

Status
Not open for further replies.

thebigcheese

Technical User
Mar 19, 2001
10
CH
I want to flag whether a sheet in a workbook has been printed or not. Whilst Excel has a BeforePrint event, I don't believe it has an AfterPrint event.

I have a procedure invoked from a button that displays the Excel Print Preview dialog. A user can Print or Close from this dialog. Is anyone aware of any code that might enable me to detect whether the user clicked on print or close?

I would use this result to flag when the sheet has been printed. I want to use this flag to warn of duplicate printing.
 
Hi
Sorry I'm not in a position to test this but if you use the BeforePrint event then you should be able to create your flag.

If your user can either print or close from the print dialog then if they choose print the BeforePrint event will fire. Put the code to create your flag in there. If tey cose cancel/close nothing will happen.
;-) If a man says something and there are no women there to hear him, is he still wrong? [ponder]
 
Hiya

Perhaps you could use the BuiltInDocumentProperty
Code:
LastPrinted
I know it's not foolproof & you can't determine which part of the workbook was printed last but at least it'll give your code some indication of whether the workbook was printed in the last few minutes or not:

Code:
MsgBox "last printed: " & ThisWorkbook.BuiltinDocumentProperties("Last Print Date")

HTH

Cheers
Nikki
 
How about designing your own form that is called when the button that currently calls up the print preview dialogue?

You could have a RefEdit control or similar for the user to select what range they wanted to print. When they've pressed OK, presuming that your code is currently in an add-in, you could store the workbook name, path and sheet name (and perhaps the range) in a sheet in your add-in.

The next time this control button is pressed you could do a look up in the add-in sheet to see whether this range/ sheet/ book combination has been printed before.

It's a bit of a judgement call as to how much Excel functionality you want to use ...
 
I have been thinking about this for a while now and could see anyway of doing it but just for fun I tried this

Sub print1()
xx = Worksheets("main").PrintPreview
If xx = False Then
'do something
Else
'do something else
End If


End Sub

If I click on close in the print preview xx=false but if I go through to print then OK it comes back true. It doesn't seem to work with printout.
I know its not quite what you wanted but this may be the start of a work around.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top