复制打印的 Word 文档并将其保存在文件夹中 [英] Make a copy of the printed Word document and save it in a folder

查看:62
本文介绍了复制打印的 Word 文档并将其保存在文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的 Word 上创建一个宏,它将打印的文档自动保存到我计算机上的另一个位置.我已经在网上和这里浏览了数百个选项,但不能完全找到我想要的.将它保存到另一个位置很容易,但只有当文档在打印队列中时才应该进行复制.有人可以帮我从这里出去吗?需要它来监控我的员工.

解决方案

使用 图 1:确保您的类模块命名正确.

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

Code 1: Put this code into a class module called "EventClassModule".

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

Code 2: Put this code into a normal module (not a class module).

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

Code 3: Put this code into "ThisDocument".

Then save, close and re-open your document. If you print it now, the event DocumentBeforePrint will execute right before printing.


Edit according comment:

Image 1: Make sure your class module is named correctly.

这篇关于复制打印的 Word 文档并将其保存在文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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