我假設您目前使用前端從網絡中提取數據。相反,考慮使用Internet Explorer對象從頁面獲取HTML:
'Declare IE object
Dim IE As Object
'Using late binding (instead of tools>>references so you don't get stuck on a version)
'Open IE
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
'Navigate to your web page so we can get the html
IE.Navigate "https://au.finance.yahoo.com/q?s=AUDUSD=X"
'Wait until its ready to go
Do While IE.busy
'Update the statusbar that we are waiting
Application.StatusBar = "Fetching stock price from yahoo"
DoEvents
Loop
'reset the statusbar
application.statusbar = False
然後使用Microsoft HTML對象庫(在工具>>業績)來解析HTML結果。
'Declare an HTML document
Dim html As HTMLDocument
'Drop html from IE to the HTMLDoc
Set html = IE.document
'Kill IE, we don't need it anymore
Set ie = Nothing
'Parse the HTML doc...
Dim objElement As HTMLObjectElement
Set objElement = html.getElementById("yfs_l10_audusd=x")
Sheet1.Range("A1").Value = objElement.innerText
一旦你得到你從網頁所需要的值,你可以把它貼在任何你喜歡的。我將它固定在Sheet1的A1範圍內
非常感謝JNevill的回答。但我仍然在努力保持進口價格的歷史記錄,隨着時間的推移。你有什麼建議嗎? – saeed 2014-10-10 22:39:30
查看http://stackoverflow.com/questions/2319683/vba-macro-on-timer-style-to-run-code-every-set-number-of-seconds-ie-120-secon瞭解如何創建一個在Excel VBA中的計時器。您可以使用此功能每隔x分鐘對網站進行ping操作並提取新的股票價格。 – JNevill 2014-10-13 13:01:21