如何使用 VBA 在 IE 中自动化下载对话框?

How can I automate the download dialog box in IE using VBA?

我是新来的,只使用 VBA 大约 6 个月。不用说,到目前为止,这里和其他一些地方的论坛帖子对我帮助很大。

我正在尝试开发一个脚本来从 Morningstar 获取数据并将其复制到 excel(注意这是我个人的非商业用途)。我相信我可以编写大部分必需的 VBA 代码,但是当 IE 下载对话框弹出时,我仍然坚持自动选择 "save"。我看过一些相关的帖子,但到目前为止我还没有能够进行逆向工程,我们将不胜感激任何帮助!

到目前为止,我对这部分的代码如下:

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()"

这就是我卡住的地方...

请注意,我使用的是 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&period=12&dataType=A&order=asc&columnYear=5&curYearPart=1st5year&rounding=3&view=raw&r=404338&denominatorView=raw&number=3")

仔细查看URL,你几乎可以更改URL中的每一个设置。

在 IE 或 Chrome 调试模式下查看 morningstar 页面后面,您可以轻松找出哪个 URL(此处用完)创建了 CSV 文件。