Hi I am trying to import data from the webpage http://www.investing.com/indices/us-spx-500-futures-historical-data What I would like to do is a macro that navigates to this webpage and select a different date range from the calendar.
I do not understand how to set the Date in the calendar. I can open it but I am not able to "replicate" the click of the mouse to select the date The code I developed up to now is:
Sub Problem()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.application")
IE.Visible = True
IE.navigate "http://www.investing.com/indices/us-30-historical-data"
'
PauseTime = 4 ' Set duration to wait in seconds.
Start = Timer ' Set start time.
Do ' While Timer < Start + PauseTime
DoEvents ' allow other processes to work (the browser to have time to load the webpage)
Loop Until IE.ReadyState = READYSTATE_COMPLETE Or Timer > Start + PauseTime
IE.Document.getElementByID("datePickerIconWrap").Click
'
End Sub
I looked in the source code of this page and I found two interesting functions, the DatePickerGetDate and DatePickerSetDate I tried to run both the scripts using
IE.Document.parentWindow.execScript "widgetHolCalendar.DatePickerGetDate", "javascript"
IE.Document.parentWindow.execScript "widgetHolCalendar.DatePickerSetDate", "javascript"
No error message is given by the code but nothing is changed so I am not sure that the code is really executing something. If I had correctly understood the code, to set a new date I have to call DatePickerSetDate with 2 arguments
DatePickerSetDate(date, shifTo)
where date is an Array of 2 elements and shifTO is a boolean. I have no idea on how to pass Arrays to this a script using vba.
Also, when I call the function DatePickerGetDate I would like to get the result and save in a vba Array
Can anyone help?