如何使用VBA在IE中自动下载对话框? [英] How can I automate the download dialog box in IE using VBA?

查看:551
本文介绍了如何使用VBA在IE中自动下载对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全是新来的,只使用VBA约6个月。不用说,这里和其他几个地方的论坛帖子已经帮助了我迄今为止。



我正在尝试开发一个脚本来从Morningstar获取数据并复制它在excel(注意这是我的个人非商业用途)。我有信心我可以编写大部分所需的VBA,但是当IE下载对话框弹出时,我坚持自动选择保存。我已经看过几个相关的帖子,但是没有我能够反向工程,任何帮助将不胜感激!



我的代码到目前为止如下:

  Sub Download_Morningstar_Data()
'
'下载晨星数据
'

my_Page =http://financials.morningstar.com/balance-sheet/bs.html?t=SCCO&region=usa&culture=en-US
设置IE = CreateObject(InternetExplorer.Application)

与IE
.Visible = True
.Navigate my_Page
Do Until .ReadyState = 4:DoEvents:Loop
结束

Application.EnableEvents = True
IE.ExecWB 17,0
直到IE.ReadyState = 4:DoEvents:Loop
IE.ExecWB 12,2

'点击导出按钮
IE.Document.parentWindow.execScriptSRT_stocFund.Export()

这就是我卡住了...



请注意我正在使用Windows 7,Excel 2010和IE11。



提前感谢

解决方案

使用



Workbooks.Open( http://financials.morningstar.com/ajax/ReportProcess4CSV.html?&t=XNYS:SCCO&region=usa&culture =的en-US&安培; CUR =安培; REPORTTYPE = BS&安培;时间段= 12&安培;的dataType = A和顺序= ASC&安培; columnYear = 5&安培; curYearPart = 1st5year&安培;舍入= 3及图=生&安培; R = 404338&安培; denominatorView =生&安培;数= 3



仔细查看网址,您可以几乎更改网址中的每个设置。



在IE或Chrome调试中查看晨星页面模式,您可以轻松找出哪个URL(这里用完了)创建了CSV文件。




I'm completely new on here and have only been using VBA for about 6 months. Needless to say, forum posts on here and a few other places have helped me immensely so far.

I'm trying to develop a script to take data from Morningstar and copy it in to excel (note this is for my personal non-commercial use). I'm confident that I can code most of the required VBA but am stuck on automating the selection of "save" when the IE download dialog box pops up. I've seen a few related posts but nothing I've been able to reverse-engineer as of yet and any help would be greatly appreciated!

My code for this part so far is as follows:

Sub Download_Morningstar_Data()
'
'  Download Morningstar Data
'

    my_Page = "http://financials.morningstar.com/balance-sheet/bs.html?t=SCCO&region=usa&culture=en-US"
    Set IE = CreateObject("InternetExplorer.Application")

    With IE
        .Visible = True
        .Navigate my_Page
        Do Until .ReadyState = 4: DoEvents: Loop
    End With

   Application.EnableEvents = True
   IE.ExecWB 17, 0
   Do Until IE.ReadyState = 4: DoEvents: Loop
   IE.ExecWB 12, 2

' click the "export" button
   IE.Document.parentWindow.execScript "SRT_stocFund.Export()"

And that's where I get stuck...

Note that I'm using Windows 7, Excel 2010 and IE11.

Thanks in advance!

解决方案

use

Workbooks.Open ("http://financials.morningstar.com/ajax/ReportProcess4CSV.html?&t=XNYS:SCCO&region=usa&culture=en-US&cur=&reportType=bs&period=12&dataType=A&order=asc&columnYear=5&curYearPart=1st5year&rounding=3&view=raw&r=404338&denominatorView=raw&number=3")

Look at the URL carefully, and you can change almost each and every settings in the URL.

Look behind the morningstar page in IE or Chrome debug mode and you can easily find out which URL (the one used up here) created the CSV file.

这篇关于如何使用VBA在IE中自动下载对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆