How to do a web query with VB and dynamic URL yahoo finance

apwdweb2003

New Member
Joined
Dec 26, 2003
Messages
6
Hi,

Thank you for all the posts on how to draw data from yahoo finance. I'm kinda new to VB and what i'm trying to do is:

Download the table (Date, price, hi, low, volume) ONLY from on this webpage.

http://finance.yahoo.com/q/hp?s=SSTI (There is a link at the bottom which allows one to download the data into a spreadsheet)


I currently have code that will draft the entire page but all i need is just this specific table. imported into sheet 2.

'Retrieve Variables to place inside a URL String
Sub getVars()
'Declare Variables for URL
Dim myURL As String
Dim Ticker As String
Dim a As String
Dim b As String
Dim c As String
Dim d As String
Dim e As String
Dim f As String
Dim g As String

'Assign values from Cells to variables
Ticker = Cells(1, 1).Value
a = Cells(3, 1).Value
b = Cells(3, 2).Value
c = Cells(3, 3).Value
d = Cells(4, 1).Value
e = Cells(4, 2).Value
f = Cells(4, 3).Value
g = Cells(6, 1).Value

'Append variables of URL to one string myURL
myURL = "http://finance.yahoo.com/q/hp?s="
myURL = myURL + Ticker + "&a="
myURL = myURL + a + "&b="
myURL = myURL + b + "&c="
myURL = myURL + c + "&d="
myURL = myURL + d + "&e="
myURL = myURL + e + "&f="
myURL = myURL + f + "&g="
myURL = myURL + g

'Test Display string myURL in a cell
Cells(15, 1).Value = myURL

'Some code i copied that will display the WHOLE HTML page in sheet 2
Dim WebCopy As Object
Set WebCopy = Sheets("Sheet2")

WebCopy.Cells.Clear

With WebCopy.QueryTables.Add(Connection:="URL;" & myURL, Destination:=WebCopy.Range("A1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SaveData = True
End With

'With Application
'.ScreenUpdating = True
'.DisplayAlerts = True
'.Calculation = xlCalculationAutomatic
'.Goto Range("A1"), True
'End With

End Sub

I tried doing a webquery except i can't cut and paste from excel into the webquery. Plus how do i get around the pop up that asks me if i want to open the file or save the file?

**I"ve tried some of the code from previous posts but can't seem to get it to work right. **

Would greatly appreciate any advice and help i can get from the experienced on this board.

Thanks in advance.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Re: How to do a web query with VB and dynamic URL yahoo fina

Hi Andrew,

Thank you for your help so far. I adjusted my code to produce a string of your specification by picking up variables in various cells on my spreadsheet. Now the challenge is how do I do a webquery to pull the full data from this URL?

I tried to do a copy and paste into the webquery unfortunately the memory of a copy is lost once i enter the webquery function.

Your advice is Greatly appreciated.

Thank you.
 
Upvote 0
Re: How to do a web query with VB and dynamic URL yahoo fina

Copy the actual text of the Hyperlink by selecting it in the Formula Bar. It will still be on the clipboard when you are in the Web Query dialog box.

Alternatively pass the text of the Hyperlink to the QueryTables.Add statement in your posted code.
 
Upvote 0

Forum statistics

Threads
1,203,180
Messages
6,053,956
Members
444,695
Latest member
asiaciara

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