VBA-发送密钥IE11保存/打开
我已经从电路板上取下代码,将密钥发送到IE11保存/打开框,当您导出文件时,该框会弹出,但不起作用(它正在发送到主浏览器)。即使手动尝试(使用ALT+S),我也无法激活“保存/打开”框并发送S按钮 是否需要一些设置才能将密钥发送到此弹出窗口 我把代码的浓缩版本放在下面 谢谢VBA-发送密钥IE11保存/打开,vba,internet-explorer-11,sendkeys,Vba,Internet Explorer 11,Sendkeys,我已经从电路板上取下代码,将密钥发送到IE11保存/打开框,当您导出文件时,该框会弹出,但不起作用(它正在发送到主浏览器)。即使手动尝试(使用ALT+S),我也无法激活“保存/打开”框并发送S按钮 是否需要一些设置才能将密钥发送到此弹出窗口 我把代码的浓缩版本放在下面 谢谢 Public Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal HWND As LongPtr) As LongPtr Sub OpenIE(
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
子下载文件()
尺寸IE作为对象,数据作为对象
作为字符串的模糊票据
设置IE=CreateObject(“InternetExplorer.Application”)
与IE
.Visible=True
.导航(“https://dillion132.github.io/default.html")
而IE.ReadyState 4
多芬特
温德
'触发下载按钮以下载文件
IE.Document.getElementbyId(“btnDowloadReport”)。单击
'等待下载提示出现
Application.Wait(现在+时间值(“00:00:03”))
'
Application.SendKeys“%{s}”
'正在等待站点加载。
“装载地点
以
设置IE=无
端接头
网页内容:
<a id="btnDowloadReport" href="https://research.google.com/pubs/archive/44678.pdf" download>Download</a>