简体   繁体   中英

Is there a DocumentAfterPrint event in MS Word?

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?

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.

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 .

我不相信任何建议的解决方法都可以在Word 2010中使用。但是,通过在documentBeforePrint事件末尾使用application.onTime()方法使另一过程要执行几秒钟,我已经取得了成功后来。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM