[英]VBA - Send Keys IE11 Save/Open
我已經從板上取下代碼以將密鑰發送到 IE11 保存/打開框,該框在您導出文件時彈出,但它不起作用(它正在發送到主瀏覽器)。 即使手動嘗試(使用 ALT + S),我也無法激活“保存/打開”框並發送 S 按鈕
您是否需要一些設置才能將密鑰發送到此彈出窗口?
我在下面放了一個精簡版的代碼
謝謝
Public Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal HWND As LongPtr) As LongPtr
Sub OpenIE()
Dim objIE As InternetExplorer
Set objIE = New InternetExplorer
Dim HWNDSrc As LongPtr
HWNDSrc = objIE.HWND
SetForegroundWindow HWNDSrc
'From https://stackoverflow.com/questions/56893185/controlling-ie11-do-you-want-to-open-save-vba
Do While objIE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
'send Alt-S to save
Application.SendKeys "%{S}"
'Make sure IE is not busy
Do While objIE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
請參考下面的示例代碼,我們可以先使用getElementbyId方法找到下載按鈕,然后點擊它顯示下載提示,然后我們可以使用Application.SendKeys "%{s}"
命令點擊保存按鈕。
Sub downloadfile()
Dim IE As Object, Data As Object
Dim ticket As String
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.navigate ("https://dillion132.github.io/default.html")
While IE.ReadyState <> 4
DoEvents
Wend
'Trigger the download button to download the file
IE.Document.getElementbyId("btnDowloadReport").Click
'wait the download prompt appear
Application.Wait (Now + TimeValue("00:00:03"))
'
Application.SendKeys "%{s}"
'Waiting for the site to load.
'loadingSite
End With
Set IE = Nothing
End Sub
網頁內容:
<a id="btnDowloadReport" href="https://research.google.com/pubs/archive/44678.pdf" download>Download</a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.