PDA

View Full Version : Solved: error handling failed



thmh
07-11-2011, 08:34 AM
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 :banghead:




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

Aflatoon
07-11-2011, 08:58 AM
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.

thmh
07-11-2011, 10:17 AM
tnx , On Error Resume Next will do