Hi Board.
I'm trying to download the csv file on this webpage through VBA.
http://www.invescopowershares.com/products/holdings.aspx?ticker=QQQ
The direct link is unobtainable (to me least) - so I was trying to create som code, that would open IE, and browse through the page untill finding the download link, download the csv file, and then close again.
But nothing seems to work - so please help!
1st option was to find the text on the page;
2nd option was to browse the page;
Again failure
Last option was to try something different... Failure too :/
So please help me out - think I've tried everything
This is Excel 2003 SP3 11.8332.8333, Internet Explorer 7.0.5730.13
I'm trying to download the csv file on this webpage through VBA.
http://www.invescopowershares.com/products/holdings.aspx?ticker=QQQ
The direct link is unobtainable (to me least) - so I was trying to create som code, that would open IE, and browse through the page untill finding the download link, download the csv file, and then close again.
But nothing seems to work - so please help!
1st option was to find the text on the page;
Code:
Sub test1()
ThisWorkbook.FollowHyperlink Address:="[URL]http://www.invescopowershares.com/products/holdings.aspx?ticker=QQQ[/URL]", NewWindow:=True
Application.Wait Now + TimeValue("00:00:05")
Application.SendKeys ("^f")
Application.SendKeys ("Download")
Application.SendKeys ("{ENTER}")
End Sub
2nd option was to browse the page;
Code:
Sub test2()
Dim ie As InternetExplorer ' Set reference Microsoft Internet Controls
Set ie = New InternetExplorer
ie.Navigate "[URL]http://www.invescopowershares.com/products/holdings.aspx?ticker=QQQ[/URL]"
'Loop unitl ie page is fully loaded
Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop
ie.Visible = True
ie.FullScreen = True
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{TAB}")
Application.Wait Now + TimeValue("00:00:01")
Application.SendKeys ("{ENTER}")
End Sub
Again failure
Last option was to try something different... Failure too :/
Code:
Sub test3()
Dim o2
Set o2 = CreateObject("internetexplorer.application")
o2.Navigate "[URL]http://www.invescopowershares.com/products/holdings.aspx?ticker=QQQ[/URL]" 'IE navigates to a webpage
o2.Visible = True 'hides IE
While o2.Busy: DoEvents: Wend
Set o = o2.Document.All.tags("A")
M = o.Length: mySubmit = -1
For r = 0 To M - 1
If InStr(1, o.Item(r).innerhtml, "Download", vbTextCompare) Then
o.Item(r).Focus
o.Item(r).Click: Exit For
End If
Next
mySleep 50 'wait five seconds
SendKeys "%S" 'Hits the save button
mySleep 50 'wait five seconds and starts typing in the path c:\test.zip to save the file
SendKeys "c"
SendKeys ":"
SendKeys "\"
SendKeys "t"
SendKeys "e"
SendKeys "s"
SendKeys "t"
SendKeys "."
SendKeys "c"
SendKeys "s"
SendKeys "v"
mySleep 10 'waits 1 second
SendKeys "%S" 'Hits the save button
SendKeys "%c" 'Hits the Close this dialog box when download completes
mySleep 20 'Waits 2 seconds and Msgbox appears: 'file exists - do you want to overwrite'
SendKeys "%y"
o2.Quit
Set o2 = Nothing
End Sub
Sub mySleep(ByVal deciSeconds As Long)
t = Timer: While Timer - t < (deciSeconds / 10): DoEvents: Wend
End Sub
So please help me out - think I've tried everything
This is Excel 2003 SP3 11.8332.8333, Internet Explorer 7.0.5730.13