控制IE11“你想打开/保存吗"VBA中的对话窗口按钮 [英] Controlling IE11 "Do you want to Open/Save" dialogue window buttons in VBA
问题描述
我们需要自动从纳斯达克网站下载文件.我现有的 VBA 代码正在打开一个 IE你想打开/保存"对话窗口.如何单击该保存按钮并通过 VBA 给出路径?我尝试了此链接中描述的各种 windows api 方法
另一种方法是发送快捷键的击键在 IE11 中单击保存按钮.我应该注意到你的 IE 窗口需要是活动窗口才能工作.因此,它在调试模式下不起作用.
下面的代码调用快捷键.我只是显示快捷键,以便您更好地了解发生了什么.
- 快捷键:Alt+S
- VBA:
Application.SendKeys "%{S}"
We need to download file from a NASDAQ website automatically. My existing VBA code is opening an IE "Do you want to Open/Save" dialogue window. How to click on that save button and give a path via VBA ? I have tried various windows api methods described in this link here also but that is giving a result of "Window Not Found".
My current code is as below:
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 workSODWeightings_20150819_NDX.xlsx"
set ieApp=Nothing
set ieDoc=Nothing
End Sub
The screenshot below shows where I have reached. How do I progress from here?
Another way to do this is to send the keystrokes of the shortcut keys to click the save button in IE11. I should note your IE window will need to be the active window for this to work. Thus, it won't work while in debug mode.
The code below calls the shortcut key. I'm just showing the shortcut key so you have a better idea what's happening.
- Shortcut key:Alt+S
- VBA:
Application.SendKeys "%{S}"
这篇关于控制IE11“你想打开/保存吗"VBA中的对话窗口按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!