控制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 work\SODWeightings_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屋!