[英]VBA - Send Keys IE11 Save/Open
I have taken code off the boards to send-Keys to the IE11 Save/Open box that pop-ups when you export a file but it is not working (it is sending to the main browser).我已经从板上取下代码以将密钥发送到 IE11 保存/打开框,该框在您导出文件时弹出,但它不起作用(它正在发送到主浏览器)。 I cannot activate the Save/Open box & send the S button even when trying manually (using ALT + S)
即使手动尝试(使用 ALT + S),我也无法激活“保存/打开”框并发送 S 按钮
Do you require some settings to be able to send keys to this pop-up?您是否需要一些设置才能将密钥发送到此弹出窗口?
I have put a condensed version of the code below我在下面放了一个精简版的代码
Thanks谢谢
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
Please refer to the following sample code, we could use getElementbyId method to find the download button first, then click it to display the download prompt, after that, we could using the Application.SendKeys "%{s}"
command to click the Save button.请参考下面的示例代码,我们可以先使用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
The web page content:网页内容:
<a id="btnDowloadReport" href="https://research.google.com/pubs/archive/44678.pdf" download>Download</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.