我在word 2010中有一个宏,它在打印文档时给文档添加了一个脚注(即在您单击“最后”打印按钮之后,在打印预览屏幕中)。
目前,为了编写文档,用户需要先运行宏,然后在运行之后,在打印文档时添加页脚。
我想自动化运行宏的部分,以便选择打印选项(Ctrl+P / File>Print)将自动运行宏,并打开打印预览屏幕进行最终打印。
这是如何做到的呢?
提前谢谢你
发布于 2018-06-11 03:16:58
http://forums.whirlpool.net.au/archive/2603917
你需要做三件事才能让它发挥作用:
通过ALT+F11打开VBA编辑器
要创建一个模块或类,右键单击并插入>>模块/类
测试:关闭、重新打开和打印
插入>>模块
Reg_Event_Handler
Dim X As New EventClassModule
Sub Register_Event_Handler()
Set X.App = Word.Application
End Sub对于这个,双击"ThisDocument“并将其粘贴到打开的框中。
Private Sub Document_Open()
Register_Event_Handler
End Sub插入>>类模块
EventClassModule
Public WithEvents App As Word.Application
Private Sub App_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
' Run code directly inside this Sub OR
MsgBox "Before Print"
' Call another Sub here, note, Sub and Module name can't match
Call Greetings
' See https://www.freesoftwareservers.com/wiki/compile-error-expected-variable-or-procedure-not-module-macros-microsoft-office-29982732.html
End Sub

https://stackoverflow.com/questions/48909968
复制相似问题