保存时调用 UserForm
当用户单击 MS Word 中的“保存”按钮时,如何在 VBA 中调用用户窗体?
How do I go about calling a userform in VBA when user clicks on the Save button in MS Word?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您有两种选择来执行此操作:您可以覆盖内置的
FileSave
和FileSaveAs
命令,也可以为应用程序的DocumentBeforeSave< 创建事件处理程序/code> 事件(还有更多工作要做)。
可以通过将以下代码添加到 VBA 模块来实现覆盖内置命令(相应地调整要显示的用户窗体的类型):
第二个选项可以通过将以下代码放置在 Microsoft Word 对象下来实现 -> VBA 编辑器中的ThisDocument:
You have two options to do that: You can either override the built-in
FileSave
andFileSaveAs
commands, or you can create an event handler for the application'sDocumentBeforeSave
event (which is a little more work to do).Overriding the built-in commands can be accomplished by adding the following code to a VBA module (adjust the type of the user form to be displayed accordingly):
The second option can be implemented by placing the following code under Microsoft Word Objects -> ThisDocument in the VBA editor:
请参阅拦截“保存”和“打印”等事件,了解应该有所帮助的示例。
See Intercepting events like Save and Print for an example that should help.