Word 2007:隐藏打印对话框

发布于 2024-12-03 08:19:58 字数 206 浏览 4 评论 0原文

我有一个 VBA 宏,可以使用不同的页面设置打印一个字母两次。这很好用。但有时(我不知道为什么)会出现打印对话框(选择打印机,...)。如何隐藏打印对话框。我喜欢在默认打印机上打印,不喜欢更改设置。

有人提出一个想法

ActiveDocument.PrintOut Background:=true

没有任何效果。

i have a vba macro that will print a letter twice with different page settings. This works great. But sometimes (i dont know why) the printing dialog (select printer, ...) appear. How can i hide the printing dialog. I like to print on the default printer and dont like to change the settings.

Somebody an idea

ActiveDocument.PrintOut Background:=true

Dont have any effect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒的傷心 2024-12-10 08:19:58

Word 允许您控制 DocumentBeforePrint 事件,该事件又提供了一种控制打印对话框显示的访问权限。该事件需要手动添加到您的 VBA 代码中。您是否控制单个文档或所有未来文档的对话框将取决于代码是否放置在单个文档或生成新文档的模板中。

将此代码添加到 ThisDocument 的 VBA 声明部分:

 Option Explicit
 Private WithEvents app As Application

然后编辑 Document_New()Document_Open() 子项以包含此行:

 Set app = Application

最后,创建 DocumentBeforePrint 子项(再次在ThisDocument) 并使用以下代码:

 Private Sub app_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)

 'Invoke your macro to print a letter twice with different settings here

 Cancel = True

 End Sub

Cancel = True 行取消标准的“打印”对话框,以便代码不会尝试两次打印文档。该解决方案运行的前提是您现有的宏打印文档,而无需通过 Dialogs(wdDialogFilePrint).Show 等方法访问打印功能,该方法将显示打印对话框。希望这有帮助。

Word lets you control the DocumentBeforePrint event, which in turn gives one access to controlling the display of the print dialog box. This event needs to be manually added to your VBA code. Whether you control the dialog for a single document or all future documents will depend on if the code is placed within a single document or the template that generates new documents.

Add this code to the VBA Declarations section for ThisDocument:

 Option Explicit
 Private WithEvents app As Application

Then edit the Document_New() and Document_Open() subs to include this line:

 Set app = Application

Finally, create the DocumentBeforePrint sub (again in ThisDocument) with the following code:

 Private Sub app_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)

 'Invoke your macro to print a letter twice with different settings here

 Cancel = True

 End Sub

The Cancel = True line cancels the standard Print dialog box, so that the code does not try to print the document twice. This solution runs on the premise that your existing macro prints a document without accessing the print function via a method such as Dialogs(wdDialogFilePrint).Show, which would display the print dialog box. Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文