Webscraping with VBA - Value Not "Sticking"

infazz

Board Regular
Joined
Sep 19, 2014
Messages
60
Hello!

I'm trying to use VBA to navigate to a webpage and download a file.
To get to the final download it has to set several parameters, including date.

My issue is that when VBA changes the text field to my desired date, the change does not stick. The textbox shows the date to be correct, but upon clicking on the text box it reverts to the previous date.

Here's what I have so far:

From the website:
Code:
input type="text" value="Oct 01, 2014" id="ctl00_PageContent_dsStartDateFilter_dateInput_text" name="ctl00_PageContent_dsStartDateFilter_dateInput_text" class="riTextBox riEnabled" style="width:100%;" maxlength="524288">

My code:
Code:
Set ie = CreateObject("InternetExplorer.Application")
    With ie
        ie.Visible = True
        ie.navigate "website.com"
        
        Do While ie.busy
            Application.StatusBar = "Downloading.."
            DoEvents
        Loop
        
        ie.navigate "website.com/nextpage"
        
        Do While ie.busy
            Application.StatusBar = "Downloading.."
            DoEvents
        Loop
        
        Set startdate = ie.document.getElementByID("ctl00_PageContent_dsStartDateFilter_dateInput_text")
        startdate.Value = "9/1/2014"
        
        Set submitbun = ie.document.getElementByID("PageContent_btnQuery")
        submitbun.Click

I've tried setting startdate.Value to "Sep 01, 2014" as well, but neither stick on the website.

Thanks!
 
Last edited:

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
It's difficult to help without the URL, but try:
Code:
startdate.focus
startdate.Value = "Sep 01, 2014"
 
Upvote 0
Thanks! When I added that line of code I got the error "Object variable or With block variable not set".
 
Upvote 0
Where have you put my code? It should replace your
Code:
startdate.Value = "9/1/2014"
i.e. when startdate references the input element.
 
Upvote 0
Like this?
Code:
Set startdate = ie.document.getElementByID("ctl00_PageContent_dsStartDateFilter_dateInput_text")
startdate.focus         
startdate.Value = "Sep 01, 2014"
If so, then I don't know the solution.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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