我們需要自動從NASDAQ網站下載文件。我現有的VBA代碼打開一個IE「你想打開/保存」對話窗口。如何點擊該保存按鈕並通過VBA提供路徑? 我也試過在這個鏈接here中描述的各種Windows API方法,但是這是給出了「未找到窗口」的結果。在VBA中控制IE11「您想打開/保存」對話窗口按鈕
我當前的代碼如下:
Sub MyIEauto()
Dim ieApp As InternetExplorer
Dim ieDoc As Object
'Dim ieTable As Object
'create a new instance of ie
Set ieApp = New InternetExplorer
'you don’t need this, but it’s good for debugging
ieApp.Visible = True
'assume we’re not logged in and just go directly to the login page
ieApp.Navigate "https://indexes.nasdaqomx.com/Account/LogOn"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop
Set ieDoc = ieApp.Document
'fill in the login form – View Source from your browser to get the control names
With ieDoc.forms(0)
.UserName.Value = "xxxxxxx"
.Password.Value = "xxxxxxx"
.submit
End With
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop
'now that we’re in, go to the page we want
ieApp.Navigate "https://indexes.nasdaqomx.com/Index/ExportWeightings/NDX?tradeDate=2015-08-19T00:00:00.000&timeOfDay=SOD/SODWeightings_2015"
'next below line commented as it is failing
'ieApp.ExecWB 4, 2, "D:\VBA code work\SODWeightings_20150819_NDX.xlsx"
set ieApp=Nothing
set ieDoc=Nothing
End Sub
下面的截圖顯示我已經到了。我如何從這裏進步?
我很困惑。事件雖然我的IE窗口是「激活」,以便廢除它的HTML,但這對我不起作用。我很困惑,因爲它在我跑過的30個測試中運行了兩次,我不確定爲什麼 – Seb
@Seb當我說激活時,我的意思是窗口有焦點。如果不同的窗口具有焦點,則SendKeys將轉到該窗口。 –