標題:
[發問]
請問如何加快股價更新?
[打印本頁]
作者:
zzoo123
時間:
2017-5-28 23:52
標題:
請問如何加快股價更新?
更新股價時 EXCEL會發生(沒有回應)
[attach]27237[/attach]
[attach]27238[/attach]
作者:
GBKEE
時間:
2017-5-29 07:56
回復
1#
zzoo123
這網址用QueryTable傳資料很慢,改用IE讀取快些
'更新按鈕
Private Sub CommandButton2_Click() '
Application.enableEvents = False
'顯示home工作表
Sheets("home").Activate
'執行更新股價程序
updatePrice
Application.enableEvents = True
End Sub
複製代碼
Sub getData(stockCode As String)
Dim Sh As Worksheet, ie
Dim i As Integer, R As Integer, C As Integer
Set Sh = ThisWorkbook.Worksheets("temp") '.Cells.Delete
Sh.UsedRange.Clear
With CreateObject("InternetExplorer.Application")
'.Visible = True
.Navigate "http://tw.stock.yahoo.com/q/q?s=" & stockCode
Do While .Busy Or .readyState <> 4: DoEvents: Loop
Set E = .Document.all.tags("TABLE")
For i = 0 To E.Length - 1
If InStr(E(i).innerText, "加到投資組合") And InStr(E(i).innerText, "成交明細") And E(i).Rows.Length > 1 Then
For R = 0 To E(i).Rows.Length - 1
For C = 0 To E(i).Rows(R).Cells.Length - 1
Sh.Cells(R + 2, C + 1) = E(i).Rows(R).Cells(C).innerText
Next
Next
End If
Next
.Quit '關閉網頁
End With
End Sub
複製代碼
作者:
zzoo123
時間:
2017-5-29 20:02
感謝幫忙 果然順多了
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)