URL link is not fully loaded when pulled, cant get loop to work

ajax1231

New Member
Joined
Sep 12, 2021
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
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 & "&region=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
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I was able to get this to partly work, but now that I have the data loaded on the page I'm lost on why it wont import the displayed webpage once loaded, any suggestions?

Sub Data()
Dim r As Long
Dim QT As QueryTable
Dim URL As String
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True


With Worksheets("Company Data")
For r = 2 To .Range("C" & .Rows.Count).End(xlUp).Row
URL = "Data Definitions" & .Range("C" & r).Value & "&region=usa&culture=en-US"
IE.navigate URL
Do While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
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
 
Upvote 0
Solution

Forum statistics

Threads
1,224,828
Messages
6,181,217
Members
453,024
Latest member
Wingit77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top