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.
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: