Word 2007:隐藏打印对话框
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Word 允许您控制 DocumentBeforePrint 事件,该事件又提供了一种控制打印对话框显示的访问权限。该事件需要手动添加到您的 VBA 代码中。您是否控制单个文档或所有未来文档的对话框将取决于代码是否放置在单个文档或生成新文档的模板中。
将此代码添加到 ThisDocument 的 VBA 声明部分:
然后编辑
Document_New()
和Document_Open()
子项以包含此行:最后,创建 DocumentBeforePrint 子项(再次在ThisDocument) 并使用以下代码:
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:
Then edit the
Document_New()
andDocument_Open()
subs to include this line:Finally, create the DocumentBeforePrint sub (again in ThisDocument) with the following code:
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 asDialogs(wdDialogFilePrint).Show
, which would display the print dialog box. Hope this helps.