Search code examples
vbainternet-explorerbuttonclick

Use VBA to click on a button in IE


I'm currently looking for a way to click on a button on a web page to automate an export.

I've already succeeded with logging in to the web page and clicking on the login button to redirect the page, but then I could not click on the next button i'm looking for.

My code :

For Each ele In IE.document.getElementsByTagName("ul")
 If ele.document.getElementsByTagName("a").getAttribute("aria-labelledby") = "Exporter vers CSV" Then ele.Click
Next

Website source:

<ul class="dropdown-menu pull-left">
   <!-- ngRepeat: item in secondaryItems track by item.dataAid --><li ng-repeat="item in secondaryItems track by item.dataAid" class="">
     <a role="button" ng-show="item.visible" aria-labelledby="Exporter vers CSV" data-aid="tool-bar-inner-dd-btn-export" type="submit" ng-disabled="!item.enabled" ng-class="{plToolbarItemDisabled:!item.enabled, disabled:!item.enabled}" class="grid-export-item-btn" ng-click="item.callback(item, $event)" pl-toolbar-button-in-dropdown="" item="item">

Solution

  • I cannot test it without knowing your URL, but this maywork:

    For Each ele In IE.document.getElementsByTagName("ul")
        For Each ele2 In ele.getElementsByTagName("a")
            If InStr(ele2.InnerHtml, "aria-labelledby=""Exporter vers CSV""") Then ele2.Click
        Next ele2
    Next ele