使用Excel PrintOut方法时,如何防止打印对话框? [英] How do you prevent printing dialog when using Excel PrintOut method

查看:2900
本文介绍了使用Excel PrintOut方法时,如何防止打印对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用PrintOut方法将Worksheet对象打印到打印机时,即使设置了DisplayAlerts = False,也会显示打印对话框(显示文件名,目标打印机,打印页面和取消按钮)。以下代码在Excel宏中工作,但如果在VB或VB.Net应用程序中使用此代码(使用Excel对象所需的参考更改),则会发生相同的情况。

When I use the PrintOut method to print a Worksheet object to a printer, the "Printing" dialog (showing filename, destination printer, pages printed and a Cancel button) is displayed even though I have set DisplayAlerts = False. The code below works in an Excel macro but the same thing happens if I use this code in a VB or VB.Net application (with the reference changes required to use the Excel object).

Public Sub TestPrint()
Dim vSheet As Worksheet

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Set vSheet = ActiveSheet
    vSheet.PrintOut Preview:=False

    Application.DisplayAlerts = True
    Application.ScreenUpdating = True

End Sub

编辑:下面的答案揭示了更多的光(这可能是一个Windows对话框而不是Excel对话框),但不回答我的问题。有没有人知道如何防止它被显示?

The answer below sheds more light on this (that it may be a Windows dialog and not an Excel dialog) but does not answer my question. Does anyone know how to prevent it from being displayed?

编辑:谢谢你的额外研究,凯文。看起来很像这是我需要的。只是不确定我想盲目接受这样的API代码。有没有人对这些API调用有任何了解,他们正在做作者的声明?

Thank you for your extra research, Kevin. It looks very much like this is what I need. Just not sure I want to blindly accept API code like that. Does anyone else have any knowledge about these API calls and that they're doing what the author purports?

推荐答案

当你说打印对话框,我假设您的意思是现在打印xxx对话框,而不是标准打印对话框(选择打印机,份数等)。以上面的例子&尝试出来,那就是我看到的行为 - 现在打印...被简短地显示然后自动关闭。

When you say the "Printing" Dialog, I assume you mean the "Now printing xxx on " dialog rather than standard print dialog (select printer, number of copies, etc). Taking your example above & trying it out, that is the behaviour I saw - "Now printing..." was displayed briefly & then auto-closed.

您尝试控制的内容可能不与Excel绑定,而是Windows级别的行为。如果可以控制,您需要a)禁用它,b)执行打印,c)重新启用。如果您的代码失败,则有可能是其他应用程序无法重新启用。

What you're trying to control may not be tied to Excel, but instead be Windows-level behaviour. If it is controllable, you'd need to a) disable it, b) perform your print, c) re-enable. If your code fails, there is a risk this is not re-enabled for other applications.

编辑:尝试此解决方案:如何在使用Excel PrintOut方法时阻止打印对话框。它似乎正好描述了你以后。

Try this solution: How do you prevent printing dialog when using Excel PrintOut method. It seems to describe exactly what you are after.

这篇关于使用Excel PrintOut方法时,如何防止打印对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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