gpt4 book ai didi

excel - 2 个 'On Error goto ' 语句中的第二个语句被忽略

转载 作者:行者123 更新时间:2023-12-02 18:53:01 25 4
gpt4 key购买 nike

我有一些代码尝试将 11x17 纸张设置为默认纸张...

        On Error GoTo PageSizeErr
ActiveSheet.PageSetup.PaperSize = xlPaperTabloid

'更多代码在这里

PageSizeErr:
On Error GoTo PageErr2
ActiveSheet.PageSetup.PaperSize = xlPaper11x17 'try another 11x17 driver definition
GoTo resumePrinting
PageErr2:
MsgBox ("There's a problem setting Tabloid paper for the printer you have selected." & Chr(10) _
& "If you have an 11x17 printer selected, please contact EMBC, otherwise, try a different printer.")
Exit Sub

--------------代码示例结束-----------------

当到达第二个“ActivateSheet.PageSetup...”行时,我没有转到 PageErr2 标签,而是收到一个错误对话框。 (我选择的打印机不支持 11x17,这是我正在尝试测试的。)

需要多个错误处理程序,因为不同的打印机驱动程序处理设置的方式似乎不同。

为什么第二个“On Error goto”语句未被识别?

最佳答案

您不能在错误处理程序中使用 on error goto。请参阅http://www.cpearson.com/excel/errorhandling.htm

也许尝试这样的事情:

Sub Tester()

Dim pSize As XlPaperSize

pSize = xlPaperTabloid


On Error GoTo haveError:
ActiveSheet.PageSetup.PaperSize = pSize
'print stuff...

Exit Sub

haveveError:
If pSize = xlPaperTabloid Then
pSize = xlPaper11x17
Resume
End If
MsgBox ("Couldn't print using tabloid or 11x17")

End Sub

关于excel - 2 个 'On Error goto ' 语句中的第二个语句被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7289220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com