I'm trying to use VBA to access a website and download some information. In the website are some drop-down boxes that need to be selected before the submit button can be clicked. I figured out one of the boxes, but the other one, which is a date, has no options in the html, even though the drop-down is populated by YYYY MMM going back for several years. I found a section of html that seems to be a function which populates the drop-down. I'm certainly not an expert at html so this is my best guess.
The following is the html for the dropdown:
<td valign="top">
<select name="dateSelect" id="dateSelect" ></select>
</td>
And the function which populates the drop-down looks like:
var dateSelect = document.getElementById("dateSelect");
//sel value = YYYYMMM
var dateYear = dateSelect.value.substr(0, 4)
var dateMonth = dateSelect.value.substr(5)
var months = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var years = new Array()
var d = new Date();
var startYear = 0;
if (d.getYear() < 2000)
startYear = d.getYear() + 1900;
else
startYear = d.getYear();
for (var a = startYear; a >= 2007; a--) {
years[startYear - a] = a;
}
function fillselboxes(theDate) {
var d = new Date();
theDate = new Date(theDate);
var dateSelect = document.getElementById("dateSelect");
for (var a = 0; a < years.length; a++) {
for (var b = months.length - 1; b >= 0; b--) {
addOption(dateSelect, years[a] + " " + months[b], years[a] + "_" + (b + 1));
}
}
dateSelect.value = years[startYear - theDate.getFullYear()] + "_" + (theDate.getMonth() + 1);
}
In my macro, I want to select last month from the dropdown. As a noob, the only thing I could think of to try was:
Dim ie as InternetExplorer
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "redacted"
Do While ie.READYSTATE <> READYSTATE_COMPLETE
DoEvents
Loop
ie.getElementById("dateselect").Value = Format(DateSerial(Year(Date), Month(Date) - 1, 1), "YYYY MMM")
When I try that, it gives me a Runtime Error '438': Object doesn't support this property or method.