我有这段代码,它应该引用公司名称的“D”列,并在 yahoo Finance 上查询股票代码。它在某些时候效果很好,其他时候我得到“选择”而不是股票代码。我不确定我做错了什么,任何帮助都将不胜感激。这是代码:
Sub Company2Ticker()
'Reference Microsoft internet internet controls and microsoft html library
For i = 2 To 3000
On Error Resume Next
If Len(Cells(i, 1).Value) = 0 Then Exit For
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
IE.navigate "http://finance.yahoo.com/lookup?s=" & Cells(i, 4).Value
Do
DoEvents
Loop Until IE.readystate = readystate_complete
Dim Doc As HTMLDocument
Set Doc = IE.document
Dim sDD As String
sDD = Trim(Doc.getElementsbyTagName("td")(2).innertext)
Cells(i, 6) = sDD
Next i
End Sub