VBA code to target java date elements and assign values


New Member
Apr 27, 2012
I am working on a VBA script (Excel 2010/Win XP) to automate downloading reports from a javascript (client-side view only) based web page and need some help.

The site has simple daily report links, but on Mondays I need the script to pull a custom report for the previous Fri-Sun's dates.

When you navigate to the custom report page, you first select an option from a table, which triggers an “onchange” event and loads start/end date fields and a dropdown options list (which is already on the correct option). You then manually enter dates (or select from java popup calendars) in the fields, in MM-DD-YYYY format, and click the submit button.

I have two questions:
1. I cannot tell what code elements to target for the date values. On the page it looks like two fields, but the code looks like maybe it's a single java element. What page element do I target to input the date values?

2. Clicking the submit button triggers a validation script that verifies the dates, and until then the input tag has a "disabled="disabled" property. Just scripting a mouse click has no effect on the page. How can I enable the button and trigger the submit?.

The VBA code for the task:
Sub ReportDownload()

Dim IE As Object
Dim today As String
Set IE = CreateObject("InternetExplorer.Application")
If WorksheetFunction.Weekday(Date) = 2 Then
    'Script to pull OnDemand report for Fri-Sun dates
    IE.navigate "http://ondemandreportpage.aspx"
    IE.Visible = True
        Do Until IE.readyState = 4: DoEvents: Loop
    IE.document.all("ctl00$ContentPlaceHolder1$lstODReportType").Value = "25"
'below is my best attempt at accessing the date fields and assigning the formatted values
 today = Format(Date, "mm-dd-yyyy")   
 IE.document.all("ctl00_ContentPlaceHolder1_SearchScrn_PnlSearch").Value = Format(today - 3, "mm-dd-yyyy")
IE.document.all("ctl00_ContentPlaceHolder1_SearchScrn_PnlSearch").Value = Format(today - 1, "mm-dd-yyyy")
'I thought this should trigger the submit button but the page doesn't register the action.   
 'rest of script for different page and works
End If

The Relevant code from the website:
******** type="text/javascript">
Sys.WebForms.PageRequestManager._initialize('ctl00$ContentPlaceHolder1$ScriptManager1', document.getElementById('aspnetForm'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tctl00$ContentPlaceHolder1$UpdatePanel1'], [], [], 90);
<div id="ctl00_ContentPlaceHolder1_UpdatePanel1">
<table style="width: 723px">
<tr style = "background-color:#D3D3D3">
<td style="width: 236px">
<b> Please Select a report Type </b>
<td style="width: 434px">
<b> Report Search Criteria </b>
<td style="width: 236px; height: 154px;">
<select  size="4" name="ctl00$ContentPlaceHolder1$lstODReportType"  onchange="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$lstODReportType\',\'\')',  0)" id="ctl00_ContentPlaceHolder1_lstODReportType"  style="height:140px;width:259px;">
<option value="2">Event Publish Count</option>
<option value="9">Escalation Report</option>
<option value="25">Daily Billing Report</option>
<td style="height: 154px" align ="center">
<td >
<span id="ctl00_ContentPlaceHolder1_lblresult" style="color:#FF3300;font-weight:bold;"></span>
<div id="ctl00_ContentPlaceHolder1_PnlSearch">
<style type="text/css">
width: 163px;
******** language="javascript" src="js/OrderValidation.js" type="text/javascript">*********>
<div id="ctl00_ContentPlaceHolder1_SearchScrn_frmDiv" style="margin-left: 40px">
<div id="ctl00_ContentPlaceHolder1_SearchScrn_PnlSearch" dir="ltr">
<h1><span  id="ctl00_ContentPlaceHolder1_SearchScrn_LblHeader"  style="font-size:Large;font-weight:bold;"></span> </h1>
<br />
<table id="ctl00_ContentPlaceHolder1_SearchScrn_TblSearch" border="0">
<td  align = "center" ><br /> <input type="image"  name="ctl00$ContentPlaceHolder1$btnSubmit"  id="ctl00_ContentPlaceHolder1_btnSubmit" disabled="disabled"  src="Images/imggenerateReport.gif" style="border-width:0px;" />  </td>

I don't know java well enough to tell, is there a way to do this or is the page coded so it can't be scripted using Excel VBA?

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Watch MrExcel Video

Forum statistics

Latest member

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