问题描述
我需要在我的 Word 上创建一个宏,它将打印的文档自动保存到我计算机上的另一个位置.我已经在网上和这里浏览了数百个选项,但不能完全找到我想要的.将它保存到另一个位置很容易,但只有当文档在打印队列中时才应该进行复制.有人可以帮我从这里出去吗?需要它来监控我的员工.
使用
I need a to create a macro on my Word which would save the printed document automatically to another location on my computer. I have looked through hundreds of options online and here also but couldn't exactly what I was looking for. Saving it to another location is easy but it should make a copy only when the the document is in the print queue. Can anyone help me out here? Need it for my employee monitoring.
Use the Application.DocumentBeforePrint event which is triggered everytime before the opened document is printed.
The following code needs to be placed in a class module, and an instance of the class must be correctly initialized.
Option Explicit
Public WithEvents App as Word.Application
Private Sub App_DocumentBeforePrint(ByVal Doc As Document, ByRef Cancel As Boolean)
Doc.SaveAs2 FileName:="your path"
End Sub
According to Using events with the Application object you need to register the event handler before it will work.
Option Explicit
Dim ThisWordApp As New EventClassModule
Public Sub RegisterEventHandler()
Set ThisWordApp.App = Word.Application
End Sub
The event DocumentBeforePrint
will work after you registered the event handler by running RegisterEventHandler
, this is recommended to run whenever the document is opened. Therefore we use the Document.Open event in ThisDocument
:
Option Explicit
Private Sub Document_Open()
RegisterEventHandler
End Sub
Then save, close and re-open your document. If you print it now, the event DocumentBeforePrint
will execute right before printing.
Edit according comment:
这篇关于复制打印的 Word 文档并将其保存在文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!