在打印 Word 文档之前运行宏 [英] Running a macro before printing a word document

查看:66
本文介绍了在打印 Word 文档之前运行宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Word 2010 中有一个宏,它会在您打印文档时为文档添加页脚(即在打印预览屏幕中单击最终"打印按钮后).

目前,为了给文档加脚,用户需要先运行宏,运行宏后,打印文档时才会添加页脚.

我想自动化运行宏的部分,以便选择打印选项(Ctrl+P/文件>打印)会自动运行宏并打开打印预览屏幕以进行最终打印.

如何做到这一点?

提前致谢

解决方案

I have a macro in word 2010, that adds a footer to documents when you print them (i.e. after you click the "final" print button, in the print preview screen).

Currently, in order to foot the document, the user needs to run the macro first, and only after running it, when they print the document, the footer is added.

I would like to automate the part of running the macro, so that selecting a printing option (Ctrl+P / File>Print) would run the macro automatically and open the print preview screen for the final printing.

How can this be done?

Thank you in advance

解决方案

http://forums.whirlpool.net.au/archive/2603917

You need to do Three things for this to work:

Open VBA Editor via ALT+F11

To create a module or class, right click and go Insert >> Module/Class

To Test: Close and Re-Open and Print

  • It should display a box saying "Before Print"

Insert >> Module

Reg_Event_Handler


Dim X As New EventClassModule
Sub Register_Event_Handler()
Set X.App = Word.Application
End Sub

For this one, Double Click "ThisDocument" and paste this in the box that opens.

Private Sub Document_Open()
Register_Event_Handler
End Sub

Insert >> Class Module

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

这篇关于在打印 Word 文档之前运行宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆