title: VBA - Click a JS button on Morningstar.com
body: <p>During my search on stackoverflow, I found a number of topics similar to this without solid answers. What I am trying to do is go to the website below and click on the "Export CSV" JS button.</p>
  
  <p>So far what I have "copied and borrowed" from another VBA Coder is:</p>
  
  <p>Sub GetDat()</p>
  
  <pre><code>Set IE = CreateObject("InternetExplorer.Application")
  
  With IE
      .Visible = True
      .navigate "http://financials.morningstar.com/ratios/r.html?t=JNJ&amp;region=USA&amp;culture=en_US"
      .Top = 50
      .Left = 530
      .Height = 600
      .Width = 1000
  
  Do Until Not IE.Busy And IE.readyState = 4
      DoEvents
  Loop
  
  End With
  
  IE.Document.getelementsbytagname("Export").Item(1).Click
  </code></pre>
  
  <p>End Sub</p>
  
  <p>I have tried delaying it by 5-10 seconds to wait for the page to load. Someone referred to the getelementsbytagname is not finding the button...?</p>
  
  <p>Also, I inspected the element of the button. The html for the button is (I added spaces to show the whole code):</p>
  
  <blockquote>
    <p>&lt; a class="large_button" href="javascript:exportKeyStat2CSV();" >&lt; span class="csv" >&lt; /span >&lt; div >Export&lt; /div >&lt; /a ></p>
  </blockquote>
  
  <p>Thank you for your time, looking forward to hearing any ideas on how I can figure this out!</p>