The second of the On Error goto statements 2 is ignored

I have a code that is trying to set 11x17 paper by default ...

        On Error GoTo PageSizeErr
        ActiveSheet.PageSetup.PaperSize = xlPaperTabloid

'more code here

PageSizeErr:
    On Error GoTo PageErr2
    ActiveSheet.PageSetup.PaperSize = xlPaper11x17  'try another 11x17 driver definition
    GoTo resumePrinting
PageErr2:
    MsgBox ("There 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

-------------- End of sample code -----------------

When it falls into the second line of ActivateSheet.PageSetup ... instead of going to the PageErr2 lable page, I get an error dialog box. (I chose a printer that does not support 11x17, which I am trying to verify.)

Multiple error handlers are needed because apparently different printer drivers handle the setting differently.

Why is the second sign of 'On Error goto' not recognized?

+3
source share
1 answer

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
+3

All Articles