Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88835

Is it possible to download a CSV file by using an Excel macro to click on a download button?

$
0
0

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.

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.

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.

<body style="overflow: hidden; padding-right: 8px;">
            <div role="presentation" class="MuiPopover-root" ... left: 0px;">
                    <div class="MuiPaper-root MuiMenu-paper MuiPaper-elevation8 MuiPopover-paper
                            MuiPaper-rounded"… transform-origin: 0px 26px;">
                    <ul class="MuiList-root MuiMenu-list MuiList-padding" role="menu" tabindex="-1">
                    ...
                    <a download="FileName.csv" class="downloadLinkButton" target="_self"
                            href="blob:https://exampleURL.com/abcdefg1234">
                    <li class="MuiButtonBase-root MuiListItem-root MuiMenuItem-root MuiMenuItem-gutters 
                            MuiListItem-gutters MuiListItem-button" tabindex="-1" role="menuitem" aria-disabled="false">Export to CSV
                            </li>
                    </a>

This is the code that I've written, but it doesn't work:

    Dim objIE As InternetExplorer 'special object variable representing the IE browser
    Dim aEle As HTMLLinkElement 'special object variable for an <a> (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 <> 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

As I mentioned, this macro doesn't error out, it just opens the browser to the webpage I want.

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).

Thank you!


Viewing all articles
Browse latest Browse all 88835

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>