title: Is it possible to download a CSV file by using an Excel macro to click on a download button?
body: <p>I want to write a macro in Excel that will download a CSV from a web application I use for my job. The user interface for the web application has you click on a button to open a menu, then click on a download button within the pop-up menu.</p>
  
  <p>I wrote a macro that's supposed to open an Internet Explorer window, then click on the download button in order to download the CSV file I want to download. I haven't been able to get it to work yet: It opens the browser to the webpage I want, but it doesn't download the CSV.</p>
  
  <p>I got the below HTML by using "Inspect Element" (I cut out parts that didn't seem relevant). Note the download button at the end.</p>
  
  <pre><code>    &lt;body style="overflow: hidden; padding-right: 8px;"&gt;
              &lt;div role="presentation" class="MuiPopover-root" ... left: 0px;"&gt;
                      &lt;div class="MuiPaper-root MuiMenu-paper MuiPaper-elevation8 MuiPopover-paper
                              MuiPaper-rounded"… transform-origin: 0px 26px;"&gt;
                      &lt;ul class="MuiList-root MuiMenu-list MuiList-padding" role="menu" tabindex="-1"&gt;
                      ...
                      &lt;a download="FileName.csv" class="downloadLinkButton" target="_self" href="blob:https://exampleURL.com/abcdefg1234"&gt;
                              &lt;li class="MuiButtonBase-root MuiListItem-root MuiMenuItem-root MuiMenuItem-gutters MuiListItem-gutters MuiListItem-button"
                               tabindex="-1" role="menuitem" aria-disabled="false"&gt;Export to CSV&lt;/li&gt;
                      &lt;/a&gt;
  </code></pre>
  
  <p>This is the code that I've written, but it doesn't work:</p>
  
  <pre><code>    Dim objIE As InternetExplorer 'special object variable representing the IE browser
      Dim aEle As HTMLLinkElement 'special object variable for an &lt;a&gt; (link) element
  
      'initiating a new instance of Internet Explorer and asigning it to objIE
      Set objIE = New InternetExplorerMedium
  
      'make IE browser visible (False would allow IE to run in the background)
      objIE.Visible = True
  
      'navigate IE to this web page
      objIE.navigate "exampleURL.com"
  
  
      Do While objIE.Busy = True Or objIE.ReadyState &lt;&gt; 4: DoEvents: Loop
  
      Set elements = objIE.Document.getElementsByTagName("a")
  
      For Each ele In elements
          If (ele.className = "downloadLinkButton") Then
              ele.Click
              Exit For
          End If
      Next ele
  </code></pre>
  
  <p>As I mentioned, this macro doesn't error out, it just opens the browser to the webpage I want.</p>
  
  <p>Does anyone have advice on how I could automate this download? 
  I'm not very familiar with how Blob URLs work, but I think that the download URL changes. (The URLs I have in the code/HTML are obviously not the real URLs).</p>
  
  <p>Thank you!</p>
  
  <p>Edit: Below is the HTML for the button which must be clicked to expand the menu that contains the "Export to CSV" option. The important part begins at <code>&lt;button class="MuiButtonBase-root MuiIconButton-root"</code></p>
  
  <pre><code>&lt;div class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-8"&gt;
          &lt;div class="MuiGrid-root MuiGrid-container MuiGrid-direction-xs-column MuiGrid-align-items-xs-flex-end"&gt;
                  &lt;div class="icon-container"&gt;
                          &lt;span class="lastupdated-container…&lt;/span&gt;
                           …
                          &lt;button class="MuiButtonBase-root MuiIconButton-root" tabindex="0" type="button" id="card-view-more" aria-label="More"&gt;
                                  &lt;span class="MuiIconButton-label"&gt;
                                          &lt;span class="material-icons MuiIcon-root" aria-hidden="true"&gt;more_vert&lt;/span&gt;
                                  &lt;/span&gt;
                          &lt;/button&gt;
                  &lt;/div&gt;
          &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>