excel 2007 vba Application.Dialogs(xlDialogPrint).Show 崩溃,如果用户选择打印预览

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3410204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:58:04  来源:igfitidea点击:

excel 2007 vba Application.Dialogs(xlDialogPrint).Show crashes if user chooses print preview

excelvbaprintingexcel-2007

提问by Kirk Hings

In Excel 2007, have a button that triggers a macro, which selects a few sheets out of many and sends to Application.Dialogs(xlDialogPrint).Show. As part of selecting the few sheets there are other macros triggered like showing certain rows, password protecting and unprotect-ing, etc.

在 Excel 2007 中,有一个触发宏的按钮,该按钮从许多工作表中选择几张并将其发送到 Application.Dialogs(xlDialogPrint).Show。作为选择几张纸的一部分,还会触发其他宏,例如显示某些行、密码保护和取消保护等。

It prints and cancels fine, except when users click the 'print preview' button in that printer dialog box. It shows the printer dialog fine, but no matter if they hit print or close it crashes.

它可以正常打印和取消,除非用户单击该打印机对话框中的“打印预览”按钮。它可以很好地显示打印机对话框,但无论是点击打印还是关闭它都会崩溃。

It appears to run through the whole macro a second time and crashes because expected values and settings are not in place like normal when it runs through the first time.

它似乎第二次运行整个宏并崩溃,因为在第一次运行时预期值和设置不像正常那样到位。

Any way to account or or capture the print preview dialog stuff when print preview is launched via the printer dialog from Application.Dialogs(xlDialogPrint).Show?

当通过 Application.Dialogs(xlDialogPrint).Show 的打印机对话框启动打印预览时,有什么方法可以计算或捕获打印预览对话框的内容?

I have tried changing passed parameters like

我试过改变传递的参数,比如

Application.Dialogs(xlDialogPrint).Show ,,,,,False
Application.Dialogs(xlDialogPrint).Show Arg6:=False

But these are not working; I've read that you can't alter the dialog anyway.

但是这些都不起作用;我读到你无论如何都不能改变对话框。

(Hope this is clear)

(希望这很清楚)

回答by Fink

Not sure if you want to show print preview directly from the button click or not. Usually I use something like this. I find it easier to view the preview first, then decide if I want to print out a hard copy. But it might not work for your situation.

不确定是否要直接通过单击按钮显示打印预览。通常我使用这样的东西。我发现先查看预览更容易,然后再决定是否要打印出硬拷贝。但它可能不适用于您的情况。

Private Sub CommandButton1_Click()

    Dim vSheets() As Variant

    vSheets = Array("Sheet1", "Sheet2")
    ActiveWorkbook.Sheets(vSheets).Select 'sheets need to be selected
    ActiveWorkbook.PrintOut preview:=True 'brings up print preview
End Sub