Hi,
I am trying to pull data from a URL, but the page takes a moment to load the data I am trying to pull. The Web Query pulls the URL before this happens. I have tried placing a readyState loop, but I am not getting the results I want (I have taken the readyState code out as I couldnt get it to work and was getting an error). Please help!
Code:
Sub Data()
Dim r As Long
Dim QT As QueryTable
Dim URL As String
With Worksheets("Company Data")
For r = 2 To .Range("C" & .Rows.Count).End(xlUp).Row
URL = "Data Definitions" & .Range("C" & r).Value & "®ion=usa&culture=en-US"
With Sheets("Company").QueryTables.Add(Connection:="URL;" & URL, Destination:=Sheets("Company").Range( _
"$A$1"))
.Name = "company_1"
.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 = True
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Next r
End With
End Sub
I am trying to pull data from a URL, but the page takes a moment to load the data I am trying to pull. The Web Query pulls the URL before this happens. I have tried placing a readyState loop, but I am not getting the results I want (I have taken the readyState code out as I couldnt get it to work and was getting an error). Please help!
Code:
Sub Data()
Dim r As Long
Dim QT As QueryTable
Dim URL As String
With Worksheets("Company Data")
For r = 2 To .Range("C" & .Rows.Count).End(xlUp).Row
URL = "Data Definitions" & .Range("C" & r).Value & "®ion=usa&culture=en-US"
With Sheets("Company").QueryTables.Add(Connection:="URL;" & URL, Destination:=Sheets("Company").Range( _
"$A$1"))
.Name = "company_1"
.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 = True
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Next r
End With
End Sub