Hello All -
I'm having a problem and hoping the smart people in this forum can help me fix it. I'm attempting to use VBA to pull data with a web query. When I first ran the macro, everything worked fine. Then I changed the date (which changes the variables in the url to pull different data) and it returned a blank page. Changing the date back to the original worked again. Then I tried a handful of other dates (including the one that didn't work earlier) and they all worked fine. I think I've got everything solved. Save and close, reopen, and nothing works again... just pulling a blank page for data. If I copy the url string and paste it into IE, I never get a blank page, just get the data that I'm looking for. Any ideas on the problem and how to fix it? Unfortunately, the website is internal so there isn't much sharing I can do to help you guys recreate the issue.
The only other idea I have that could be causing the problem is that when I paste the url manually into IE, the page redirects twice before showing the data back on the original url again. I feel like this could be the cause of the problem, but doesn't seem to explain why it was working (mostly) during testing and not working later. Any help is much appreciated.
I'm having a problem and hoping the smart people in this forum can help me fix it. I'm attempting to use VBA to pull data with a web query. When I first ran the macro, everything worked fine. Then I changed the date (which changes the variables in the url to pull different data) and it returned a blank page. Changing the date back to the original worked again. Then I tried a handful of other dates (including the one that didn't work earlier) and they all worked fine. I think I've got everything solved. Save and close, reopen, and nothing works again... just pulling a blank page for data. If I copy the url string and paste it into IE, I never get a blank page, just get the data that I'm looking for. Any ideas on the problem and how to fix it? Unfortunately, the website is internal so there isn't much sharing I can do to help you guys recreate the issue.
Code:
Sub Build_WQ()
'Delete all Web Queries
Call Delete_WQ
'Holds web query link
Dim WQ_Hx As String
'Turn off Screen Updating
Application.ScreenUpdating = False
'Status Bar Message
Application.StatusBar = "Be patient while web query loads..."
'Clears the contents of PPR Sheet
Worksheets("Gensuite Pull").Cells.Clear
'Built Web Query Link Address for hour that corresponds with loop
WQ_Hx = Sheets("Hidden").Range("A1").Value
'Creates WebQuery based on link value in WQ_Hx variable
www = "URL;" & WQ_Hx
With Worksheets("Gensuite Pull").QueryTables.Add(Connection:=www, Destination:=Worksheets("Gensuite Pull").Range("A1"))
.Name = "WebQuery"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.Refresh BackgroundQuery:=False
End With
'Status Bar Message
Application.StatusBar = "Building Gensuite Data Tables...Complete"
'Reset Status Bar
Application.StatusBar = False
End Sub
The only other idea I have that could be causing the problem is that when I paste the url manually into IE, the page redirects twice before showing the data back on the original url again. I feel like this could be the cause of the problem, but doesn't seem to explain why it was working (mostly) during testing and not working later. Any help is much appreciated.