The following query works ok, but it sometimes gets stuck and hangs for a long time. What can I add so that if the query gets stuck it will timeout and move on to the next query? I have noticed that when it does get stuck that it is on the line that reads .Refresh BackgroundQuery:=False
Sub wbquery()
Dim n As Integer
For n = 1 To 100
With ActiveSheet.QueryTables.Add(Connection:=“URL;” & “Wikipedia, the free encyclopedia” & n & “”, _
Destination:=ActiveSheet.Range(“A65000”).End(xlUp).Offset(1, 0))
.Name = “myquery”
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
.Delete
End With
Next n
End Sub