Short version
I played with this a bit and got roughly the same results as you did, which is, it only returned the first stock I selected, not all of them. I changed things a bit and was able to get all the quotes. Instead of a putting the text into textbox, use a RichTxtBox.
Long version
I'm a little more partial to the
WebBrowser [COLOR=000090](Microsoft Web Browser -
shdocvw.dll)[/color] as it seems easier to work with, so I used that instead. Here's what I did:
- Opened a new workbook
- Opened Visual Basic Editor (ALT+F11)
- Inserted a UserForm
- Right-clicked the toolbox, selected [COLOR=000090]
[/color]
- Added the [COLOR=000090]
Code:
Microsoft Rich Textbox Control
[/color] (
richtx32.ocx)
and the [COLOR=000090]
[/color](
shdocv.dll) to the toolbox
- Added the RichTextBox and WebBrowser controls to the UserForm
- Inserted a module
- Added the following code to the module:
Code:
Sub getUnparsedStockQuotes()
Dim stockQuotes(20) As String
Dim myList As String
Dim URL As String
Dim idx As Integer
stockQuotes(1) = "AMD"
stockQuotes(2) = "INTC"
stockQuotes(3) = "^DJI"
stockQuotes(4) = "^IXIC"
stockQuotes(5) = "GE"
For idx = 1 To UBound(stockQuotes)
If stockQuotes(idx) <> "" Then
If idx = 1 Then
myList = stockQuotes(idx)
Else
myList = myList & "+" & stockQuotes(idx)
End If
End If
Next
URL = "[URL unfurl="true"]http://finance.yahoo.com/q?d=t&s="[/URL] & myList
Call Get_Info_Using_Normal_Method(URL)
'UserForm1.Show
End Sub
Public Sub Get_Info_Using_Normal_Method(URL As String)
With UserForm1
.WB.Navigate URL
Do Until .WB.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
.rtf1.Text = UserForm1.WB.Document.documentElement.outerText
'.rtf1.Text = UserForm1.WB.Document.documentElement.innerHTML
End With
End Sub
Now all you have to do is parse out the info you want.
I commented out the
UserForm1.Show statement, because there is no real reason to show the text.
I threw in the commented out line about the HTML code, in case that's what you're really after.
Since a simple Google query, such as
Excel stock quotes turns up a lot of pre-written code examples. I assume this is either for a school project, your own edification, or a very specific need.
Stephen F. Van Buren