tags:

views:

175

answers:

2

I am working on a project where I need to return a word document back to a certain state after it is printed. I have found a DocumentBeforePrint event but I cannot find a DocumentAfterPrint event. Is it poorly documented or is there some other workaround that exists?

+2  A: 

Here is one workaround based on subroutine names. I do not believe there is a specific DocumentAfterPrint event like you desire. Here's the code:

Sub FilePrint()
'To intercept File > Print and CTRL-P'

MyPrintSub

End Sub

Sub FilePrintDefault()
'To intercept the Standard toolbar button'

MyPrintSub

End Sub

Sub MyPrintSub()

Dialogs(wdDialogFilePrint).Show
'Your code here, e.g:'
MsgBox "I am done printing."

End Sub

UPDATE: Please note the gotchas in Will Rickards' answer below.

pianoman
+1  A: 

Looking at the application events I don't see it. I don't see it in the document events either. Please note on the workaround provided above, that is using the FilePrint and FilePrintDefault methods, you should read this site. These methods replace the built-in function. So you actually need to add code in there or have it generated for you to get word to actually print. Also background printing can cause your code to execute before it has finished printing. If you really must run something after it has printed you'll need to disable background printing.

Will Rickards