I have a macro that runs several web queries on ticker symbol in a list. It returns the query data for a symbols then loops to the next symbol. While not extremely fast or efficient it gets the job done...until it has a web connection failure (usually a timeout issue) and at that point the macro just stops and reports the error. At this point I have to run the macro again on the entire set of ticker symbols.
Is there some additional code I can use that will allow the macro to "try again" instead of just stopping. I have thought about "On Error Resume Next" but I do not know enough about VBA to make it work.
TIA
Here is a sample of the code:
' Retrieve data for each symbol
For Each c In rng
If IsEmpty(c.Value) Then Exit For
' This query will retrieve the annual returns
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.smartmoney.com/fundsnapshots/index.cfm?story=return&symbol=" & c.Value _
, Destination:=Worksheets("Data").Range("B" & Application.WorksheetFunction.Match(c.Value, dtrng, 0)))
.Name = "Annual Returns for " & c.Value
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "17"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With
Is there some additional code I can use that will allow the macro to "try again" instead of just stopping. I have thought about "On Error Resume Next" but I do not know enough about VBA to make it work.
TIA
Here is a sample of the code:
' Retrieve data for each symbol
For Each c In rng
If IsEmpty(c.Value) Then Exit For
' This query will retrieve the annual returns
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.smartmoney.com/fundsnapshots/index.cfm?story=return&symbol=" & c.Value _
, Destination:=Worksheets("Data").Range("B" & Application.WorksheetFunction.Match(c.Value, dtrng, 0)))
.Name = "Annual Returns for " & c.Value
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "17"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With