Hi,
I'm using VBA to access a webpage and run a report that requires user defined fields. After the report generates on the website, I want to export CSV. The website is a SQL server site that contains pre-built queries for non-coders. I successfully wrote code below that takes me to the site and enters date values ("12/21/16") and ("2155"). The report generates, but I don't know how to have it export to CSV. I know you can write the website code and then simply type ".csv" at the end of the URL, but that doesn't work here because first the code needs to run and enter the date parameter and "2155" into fields on the SQL server site.
How can I extract data from a website using VBA, OTHER than using the ".csv" after the URL approach?
The javascript code on the site uses this to export to CSV. On the front end, there is a button I can click to export to CSV, but it has no ID code, so I can't reference it in VBA to click and download (in my VBA code below, I successfully do this in the Click the "View Report" button section).
Also, for security reasons, I did not include the real website URL below.
JavaScript from site that allows user to export data to CSV:
function *******()
{
$find('ReportViewerControl').exportReport('CSV');
}
My VBA that successfully allows me to access the site, enter user inputs, and generate data on the SQL webpage:
Sub test()
' open IE, navigate to the desired page and loop until fully loaded
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
my_url = "http://XXXXXXXXXXX/ReportServer/Pag...Finance_MO/Transaction_List&rs:Command=Render"
With ie
.Visible = True
.Navigate my_url
.Top = 50
.Left = 530
.Height = 400
.Width = 400
Do Until Not ie.Busy And ie.ReadyState = 4
DoEvents
Loop
End With
' Input the start date, end date, and relationship number
Call ie.Document.getElementById("ReportViewerControl_ctl04_ctl03_txtvalue").SetAttribute("value", "12/21/16")
Call ie.Document.getElementById("ReportViewerControl_ctl04_ctl05_txtvalue").SetAttribute("value", "12/21/16")
Call ie.Document.getElementById("ReportViewerControl_ctl04_ctl07_txtvalue").SetAttribute("value", "2155")
' Click the "View Report" button
ie.Document.getElementById("ReportViewerControl_ctl04_ctl00").Click
Do Until Not ie.Busy And ie.ReadyState = 4
DoEvents
Loop
'Download data (NEED HELP FROM MR. EXCEL TO FINISH THIS SECTION
End Sub
Does anyone know how to help me complete the final section? I've looked and can't find anything already posted. It's essentially data sitting on the webpage above, but the data only exists on the original URL (my_url variable above) after the Call inputs have been added.
I'm using VBA to access a webpage and run a report that requires user defined fields. After the report generates on the website, I want to export CSV. The website is a SQL server site that contains pre-built queries for non-coders. I successfully wrote code below that takes me to the site and enters date values ("12/21/16") and ("2155"). The report generates, but I don't know how to have it export to CSV. I know you can write the website code and then simply type ".csv" at the end of the URL, but that doesn't work here because first the code needs to run and enter the date parameter and "2155" into fields on the SQL server site.
How can I extract data from a website using VBA, OTHER than using the ".csv" after the URL approach?
The javascript code on the site uses this to export to CSV. On the front end, there is a button I can click to export to CSV, but it has no ID code, so I can't reference it in VBA to click and download (in my VBA code below, I successfully do this in the Click the "View Report" button section).
Also, for security reasons, I did not include the real website URL below.
JavaScript from site that allows user to export data to CSV:
function *******()
{
$find('ReportViewerControl').exportReport('CSV');
}
My VBA that successfully allows me to access the site, enter user inputs, and generate data on the SQL webpage:
Sub test()
' open IE, navigate to the desired page and loop until fully loaded
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
my_url = "http://XXXXXXXXXXX/ReportServer/Pag...Finance_MO/Transaction_List&rs:Command=Render"
With ie
.Visible = True
.Navigate my_url
.Top = 50
.Left = 530
.Height = 400
.Width = 400
Do Until Not ie.Busy And ie.ReadyState = 4
DoEvents
Loop
End With
' Input the start date, end date, and relationship number
Call ie.Document.getElementById("ReportViewerControl_ctl04_ctl03_txtvalue").SetAttribute("value", "12/21/16")
Call ie.Document.getElementById("ReportViewerControl_ctl04_ctl05_txtvalue").SetAttribute("value", "12/21/16")
Call ie.Document.getElementById("ReportViewerControl_ctl04_ctl07_txtvalue").SetAttribute("value", "2155")
' Click the "View Report" button
ie.Document.getElementById("ReportViewerControl_ctl04_ctl00").Click
Do Until Not ie.Busy And ie.ReadyState = 4
DoEvents
Loop
'Download data (NEED HELP FROM MR. EXCEL TO FINISH THIS SECTION
End Sub
Does anyone know how to help me complete the final section? I've looked and can't find anything already posted. It's essentially data sitting on the webpage above, but the data only exists on the original URL (my_url variable above) after the Call inputs have been added.