Sub Macro1() Dim URL As String Dim Path As String Dim i As Integer For i = 2 To 50 If Range("Prices!E" & i).Value <> 1 Then URL = Range("Prices!D" & i).Text Path = Range("Prices!F" & i).Text End If Sheet19.Activate With ActiveSheet.QueryTables.Add(Connection:= _ "URL;" & URL _ , Destination:=ActiveSheet.Range("$A$1")) .Name = _ "" & Path .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
The above code creates an error on the specified line. A google search in .Refresh BackgroundQuery shows that it is legible in its functions in loops. Just deleting a line does not display anything in excel.
With the current error message, the code works fine for the first value I and then it breaks.
For the answer and comments - TL; DR: .Refresh BackgroundQuery: = False will not work if your request is invalid or incorrect. The problem in this case was this: ... the next loop called cells used as URLs that did not pass any values ββto them. However, it will fail at any time when the request is malformed.
source share