Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 第二个2';错误转到';语句被忽略_Excel_Vba - Fatal编程技术网

Excel 第二个2';错误转到';语句被忽略

Excel 第二个2';错误转到';语句被忽略,excel,vba,Excel,Vba,我有一些代码试图将11x17纸张设置为默认值 On Error GoTo PageSizeErr ActiveSheet.PageSetup.PaperSize = xlPaperTabloid '这里有更多代码 PageSizeErr: On Error GoTo PageErr2 ActiveSheet.PageSetup.PaperSize = xlPaper11x17 'try another 11x17 driver definiti

我有一些代码试图将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”时。。。行,而不是进入PageError2标签,我得到一个错误对话框。(我选择了一台不支持11x17的打印机,这正是我要测试的。)

由于不同的打印机驱动程序处理设置的方式不同,因此需要多个错误处理程序


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

您不能在错误处理程序中使用On Error goto。 看

也许可以试试这样:

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
只需将第二个“错误转到”更改为转到,即可完成。