yousey88
yousey88

Reputation: 3

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

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!

Upvotes: 0

Views: 3105

Answers (1)

cyboashu
cyboashu

Reputation: 10433

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.

enter image description here

Upvotes: 1

Related Questions