我已经从电路板上删除了发送的代码-当你导出一个文件但它不工作(它正在发送到主浏览器)时,弹出的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发布于 2020-01-06 16:35:15
请参考以下示例代码,我们可以先使用getElementbyId方法找到download按钮,然后单击它显示下载提示,然后使用Application.SendKeys "%{s}"命令单击Save按钮。
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>https://stackoverflow.com/questions/59606566
复制相似问题