How do you prevent printing dialog when using Excel PrintOut method

强颜欢笑 提交于 2019-12-01 17:28:18

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.

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.

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

Raghbir Singh

If you don't want to show the print dialogue, then simply make a macro test as follows; it won't show any print dialogue and will detect the default printer and immediately print.

sub  test()

 activesheet.printout preview:= false

end sub

Run this macro and it will print the currently active sheet without displaying the print dialogue.

The API calls in the article linked by Kevin Haines hide the Printing dialog like so:

  1. Get the handle of the Printing dialog window.
  2. Send a message to the window to tell it not to redraw
  3. Invalidate the window, which forces a redraw that never happens
  4. Tell Windows to repaint the window, which causes it to disappear.

That's oversimplified to put it mildly.

The API calls are safe, but you will probably want to make sure that screen updating for the Printing dialog is set to True if your application fails.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!