Solved

Automating Internet Explorer through Excel VBA

Posted on 2015-02-20
8
331 Views
Last Modified: 2016-02-10
Hi,

I am new to working with Internet Explorer inside of Excel. I have a VBA code that successfully logs into Morningstar.com's website and then goes to a specific URL that displays Income Statement data for a specific stock. I now need to have the VBA code to click on the "Export" button on this URL. After looking through the source code for this page, I cannot find the name or any mention of the export button.

The URL I am interested in is:
http://financials.morningstar.com/income-statement/is.html?t=AAP®ion=usa&culture=en-US

The export button is on the top of the data table on the far right hand side. I would use similar code that I have for clicking on the "Login" button on the login screen. It looks like:

 Set inputCollection = appIE.document.getElementsByTagName("input")
   
    ' click the export button
    For Each inputElement In inputCollection
      If inputElement.getAttribute("name") = "export_button" Then   'don't know what the name is for the export button
        inputElement.Click
        Exit For
      End If
    Next inputElement

I would appreciate any help. Thanks!
0
Comment
Question by:ttbengineer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 28

Assisted Solution

by:omgang
omgang earned 250 total points
ID: 40621568
I used Chrome Developer tools to locate the Export button.  See attached image.
OM Gang

Export button in source code
0
 

Author Comment

by:ttbengineer
ID: 40621654
Thanks for the info, OM Gang!

So if I use the code I listed, what would be the element by tag name? I assumed it would be "input", so I would use something like the following to loop through the elements and find the export button:

Set inputCollection = appIE.document.getElementsByTagName("input")
     
     ' click the export button
     For Each inputElement In inputCollection
       If inputElement.getAttribute("name") = "exportButton" Then  
         inputElement.Click
         Exit For
       End If
     Next inputElement

I tried this but it still doesn't click on the export button. Any ideas on what I'm doing wrong here?
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40621675
You don't need to go thru all the stuff, just call
appIE.document.getelementsbyname('sfcontent').Item(0).getElementsByClassName('rf_export').Item(0).click()

Open in new window

Note that you need to provide the innermost class, as only that one has an action.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:ttbengineer
ID: 40621771
Qlemo,

I tried adding this and I am getting a compile error. The workbook is attached.

Thanks
Morningstar-Download.xlsm
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 250 total points
ID: 40621796
Hmm, I tried with PowerShell, and the exposed interface is different ...
You can use this instead:
appIE.document.getElementsByClassname("rf_export").Item(0).Click

Open in new window

0
 

Author Comment

by:ttbengineer
ID: 40621868
Qlemo, that worked!

Now how can I call the "Open" button on the open or save message that pops up?
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40621881
You can't, and that is intentional. In IE you do not get access to the download overlay bar. Otherwise a script could download a file without you knowing it.
0
 

Author Comment

by:ttbengineer
ID: 40622054
Okay. Thank you guys for the help!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question