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:

Some videos you may like

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,419
It's difficult to help without the URL, but try:
Code:
startdate.focus
startdate.Value = "Sep 01, 2014"
 

infazz

Board Regular
Joined
Sep 19, 2014
Messages
60
Thanks! When I added that line of code I got the error "Object variable or With block variable not set".
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,419

ADVERTISEMENT

Where have you put my code? It should replace your
Code:
startdate.Value = "9/1/2014"
i.e. when startdate references the input element.
 

infazz

Board Regular
Joined
Sep 19, 2014
Messages
60
I added it before "startdate.value" as shown in your prior post.
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,419
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,108,910
Messages
5,525,585
Members
409,651
Latest member
Quasar Hunter

This Week's Hot Topics

Top