-
Solved: error handling failed
below is macro with 2 errors and 2 On Error GoTo lines , macro stops at second error , can someone tell me why this macro fails to exit without error
[vba]
Sub error_handling()
On Error GoTo skip1
'Application.ScreenUpdating = False
With ActiveSheet.QueryTables.Add(Connection:= _
Range("k2") _
, Destination:=Range("A1"))
.Name = "Quote:"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = False
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24"
.WebPreFormattedTextToColumns = False
.WebConsecutiveDelimitersAsOne = False
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
'Application.ScreenUpdating = True
skip1:
'On Error GoTo 0
On Error GoTo skip2
'Application.ScreenUpdating = False
With ActiveSheet.QueryTables.Add(Connection:= _
Range("k3") _
, Destination:=Selection)
.Name = "Quote:"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = False
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24"
.WebPreFormattedTextToColumns = False
.WebConsecutiveDelimitersAsOne = False
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
'Application.ScreenUpdating = True
skip2:
End Sub
[/vba]
-
As soon as you use On Error Goto label, everything that follows that label, when you jump there due to an error, is an error handler until you either exit the sub, or run a Resume statement. Any error inside an error handler will cause a run time error. It appears to me that you just want an On Error Resume Next at the top of your sub.
-
tnx , On Error Resume Next will do
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules