Error when trying to set attribute of a Java element - date

TracyReader1

New Member
Joined
May 30, 2014
Messages
3
Hi,

I want to download a bunch of data from the following website:BM Unit Data
I can only download a day at the time, and a unit at the time, so I don't want to do this by hand.

I've written a sub that goes to the website and sets the attributes in Java. This works for everything but the settlement date, the code for that executes, but nothing happens - the value of the element doesn't change. I've tried manually setting the date in the webpage, then getting the value of the element, and the date format I'm setting looks identical.

It doesn't even produce an error, nothing happens to the element, and then when I try to download the unit data I get a message telling me that I need to choose a settlement date.

The code that has no result is
<code>IEdoc.Getelementbyid("param5").setattribute "Value", Format(day, DtFmt$)</code>

I've tried replacing day with an actual date string ("2014-07-01") - no effect.

The full sub is:
<code>
Option Explicit


Const URL$ = "http://www.bmreports.com/servlet/com.logica.neta.bwp_PanBMUData"
Const DtFmt$ = "yyyy-mm-dd"

Sub GetUnitData(StartDate As Date, EndDate As Date, rUnits As Range) 'Tracy Wilkinson 28 July 2014
'Operates the website
Dim IE As Object
Dim IEdoc As Object
Dim u As Range, day As Date, DayFmt As Object
Dim theFrame As Object
Dim Name$

Set IE = CreateObject("InternetExplorer.Application")


With IE
.Visible = True
.Navigate URL$
While IE.Busy
DoEvents 'wait until IE is done loading page.
Wend
While IE.readyState <> 4
DoEvents
Wend
End With
Set theFrame = IE.document.getelementsbyname("topFrame")(0)
Set IEdoc = theFrame.ContentWindow.document
'Set the parameters that are the same for each download
IEdoc.Getelementbyid("param6").setattribute "value", "*"
IEdoc.Getelementbyid("fieldsetdatatypes").setattribute "value", "/servlet/com.logica.neta.bwp_PanBMDataServlet"


'For each day (go in day order because lots of units)
For day = StartDate To EndDate
'Set up date in Javascript
IEdoc.Getelementbyid("param5").Focus
Name$ = Format(day, DtFmt$)
IEdoc.Getelementbyid("param5").setattribute "Value", Format(day, DtFmt$)
IEdoc.Getelementbyid("param5").setattribute "Value", "'" & Name$ & "'"


For Each u In rUnits
IEdoc.Getelementbyid("param1").setattribute "value", u.Value


IEdoc.Getelementbyid("go_button").Click
While IE.Busy
DoEvents 'wait until IE is done loading page.
Wend
While IE.readyState <> 4
DoEvents
Wend


Next u

Next day


End Sub</code>

rUnits is a list of unit names in an excel worksheet that I want the macro to loop through, downloading.
 
Last edited:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
For some reason, this morning this code is working:

<code> IEcontrol.Getelementbyid("param5").Focus' IE.Navigate "javascript:_doPostBack('calendar3'"
Name = Format(day, DtFmt$)
'Name$ = IEcontrol.Getelementbyid("param5").getattribute("Value")
IEcontrol.Getelementbyid("param5").setattribute "value", Name</code>

(Name is declared as a variant).

I'm holding my breath.
 
Upvote 0

Forum statistics

Threads
1,216,590
Messages
6,131,614
Members
449,658
Latest member
JasonEncon

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