Download csv file from webpage

FrZ

New Member
Joined
Mar 5, 2008
Messages
5
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;

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
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,215,632
Messages
6,125,909
Members
449,274
Latest member
mrcsbenson

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