如何在保存前在 Word 中运行宏? [英] How to run a macro in Word before save?
本文介绍了如何在保存前在 Word 中运行宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何让 Microsoft Word 在每次保存任何文档之前都运行 VBA 宏?可以在不向文档本身添加宏的情况下完成吗?
How to make Microsoft Word to run a VBA macro every time before any document is saved? Could it be done without adding macros into the document itself?
推荐答案
您可以在 Document_Open
中使用 WithEvents
变量和常规方法名称(>VariableName_EventName
).也适用于模板.
You can subscribe to application events in Document_Open
by using WithEvents
variable and conventional method names (VariableName_EventName
). Works in templates as well.
您可以将此代码放入ThisDocument
对象中,或按照此处.
You can put this code into ThisDocument
object, or make a separate class module as described here.
Private WithEvents App As Word.Application
Private Sub Document_Open()
Set App = Word.Application
End Sub
Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
MsgBox("BeforeSave")
End Sub
这篇关于如何在保存前在 Word 中运行宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文