简体   繁体   English

MS Word中是否有DocumentAfterPrint事件?

[英]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. 我正在做一个项目,在该项目中,Word文档需要在打印后返回到特定状态。 I have found a DocumentBeforePrint event but I cannot find a DocumentAfterPrint event. 我找到了DocumentBeforePrint事件,但是找不到DocumentAfterPrint事件。 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. 我认为没有您想要的特定DocumentAfterPrint事件。 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. 更新:请注意下面的Will Rickards回答中的陷阱。

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 . 请注意上面提供的解决方法,即使用FilePrint和FilePrintDefault方法,您应该阅读此站点 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()方法使另一过程要执行几秒钟,我已经取得了成功后来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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