Multiple On Error Goto Statements
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn
On Error Resume Next
more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up The second of 2 'On Error goto ' statements gets http://www.ibm.com/support/knowledgecenter/SSVRGU_9.0.0/com.ibm.designer.domino.main.doc/LSAZ_MULTIPLE_ON_ERROR_STATEMENTS.html ignored up vote 2 down vote favorite I have some code that tries to set 11x17 paper as a 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's a problem setting Tabloid paper for the printer you have selected." & Chr(10) _ & "If you have an http://stackoverflow.com/questions/7289220/the-second-of-2-on-error-goto-statements-gets-ignored 11x17 printer selected, please contact EMBC, otherwise, try a different printer.") Exit Sub -------------- end of code sample ----------------- When it gets to the second 'ActivateSheet.PageSetup... line, instead of going to PageErr2 lable I get an error dialog box. (I have a printer selected that doesn't support 11x17 which is what I'm trying to test for.) The multiple error handlers are needed as it seems that different printer drivers handle the setting the differently. Why doesn't the second 'On Error goto ' statement get recognized? excel-vba share|improve this question edited Sep 2 '11 at 21:15 Mike Sherrill 'Cat Recall' 54.2k755102 asked Sep 2 '11 at 21:06 Greg 1112 1 Just change your second "on error goto" to a goto and you're done. –Kevin Sep 2 '11 at 21:27 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote You can't use on error goto within an error handler. See http://www.cpearson.com/excel/errorhandling.htm Maybe try something like this: 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 share|improve thi
Error GoTo commands, but If one error appear the next error results in Run-time error 91. Do I have to rese something after each check (...and in case, what?)? Thanks, Erlend Dim test1, test2, test3 Sub checkk() test1 http://www.pcreview.co.uk/threads/on-error-goto-how-to-use-multiple.974111/ = False test2 = False test3 = False check1: On Error GoTo check2 Columns("B").Find(What:="length").Activate test1 = True http://www.teachexcel.com/excel-help/excel-how-to.php?i=281881 check2: On Error GoTo check3 tab1start = Columns("A").Find(What:="md").Row test2 = True check3: On Error GoTo stopp tab2start = Columns("B").Find(What:="east").Row test3 = True stopp: If Not test3 Then MsgBox "Unknown format" Exit Sub End If End Su -- Message posted from http://www.ExcelForum.com e18, Apr 13, 2004 #1 Advertisements e18 Guest ...I have tried with *Err.Clear* with no luc -- Message posted from http://www.ExcelForum.com e18, on error Apr 13, 2004 #2 Advertisements e18 Guest I could of course use *On Error Resume Next* (tab1start and tab2star are equal to zero if Columns.Find not found) as a workaround, but still would very much like an answer to how to have more than one *O Error GoTo* in a macro. Thank you. Erlen -- Message posted from http://www.ExcelForum.com e18, Apr 13, 2004 #3 Tom Ogilvy Guest Dim rng1 as Range, rng2 as Range set rng1 = Columns(1).Find("Start") set rng2 on error goto = Columns(1).Find("End") if not rng1 is nothing then msgbox "Start at " & rng1.row End if if not rng2 is nothing then msgbox "End at " & rng2.row End if This doesn't raise an error if the search term isn't found. -- Regards, Tom Ogilvy "e18 >" <<> wrote in message news:... > I could of course use *On Error Resume Next* (tab1start and tab2start > are equal to zero if Columns.Find not found) as a workaround, but I > still would very much like an answer to how to have more than one *On > Error GoTo* in a macro. > > Thank you. > > Erlend > > > --- > Message posted from http://www.ExcelForum.com/ > Tom Ogilvy, Apr 13, 2004 #4 Alan Beban Guest Tom Ogilvy provided some code to avoid your problem. Nevertheless, I have inserted some code in your originally provided code to illustrate one way to have multiple On Error statements executed. You need to resume execution (i.e., exit the error handler) after entering each error handler. Alan Beban e18 < wrote: > I wan't to use multiple On Error GoTo commands, but If one error appear, > the next error results in Run-time error 91. Do I have to reset > something after each check (...and in case, what?)? > > Thanks, Erlend > > > Dim test1, test2, test3 > > Sub checkk() > Dim test1, test2, test3 > test1 = False >
processing, and closes them. Sometimes, 1 or more of these files could be missing (for whatever reason, the files are not in my control) I put On Error Goto on the inside of the loop that opens the files. This works fine for 1 missing file. If there are 2 missing files, the procedure fails when it encounter the second missing file in the loop. Here is quick sketch of my loop. For x = 1 to 10 on error goto nt open file process data in file close file nt: Next x Suggestions for the 2nd or more missing files situations? thanks Free Excel Help Forum - Ask any question about Excel and have it answered in no time. Similar Excel Tutorials Combine Worksheets from Multiple Workbooks into One Excel macro that allows you to select multiple workbooks and have all of their worksheets automatically combined in ... Simplify VBA Coding for Common Functions ' These modules exist just to make other VBA code easier to write and more readable ' For example, you can just ent ... Error bars in Charts in Excel How to add, manage, and remove error bars in charts in Excel. Error bars allow you to show the potential variance ... Prevent Errors From Appearing in Excel How to prevent errors from appearing in formulas in Excel. This is especially helpful for the Vlookup function. Sec ... Helpful Excel Macros Close a Workbook after a Time Limit is Reached - This macro will automatically close the workbook in which it is located after that workbook has been opened for a certai Combine Multiple Workbooks into One - This macro for Microsoft Excel allows you to combine multiple workbooks and worksheets into one new workbook and workshe Open a PowerPoint Presentation from Excel - This free macro for Microsoft Excel allows you to open any PowerPoint presentation from excel. You can change the file Excel Macro to Save a Specific Worksheet as a New File - This Excel Macro allows you to save a specific worksheet within the Excel Workbook to its own new file. You will be a Open any Program from Excel - This free excel macro allows you to open any program on your computer from excel. You c