I am trying to send an email over Microsoft 365 using IE as the browser. I am currently having difficulty getting VBA to create a new email and am trying to do so by simply telling it to click the "New Mail" button which has the following HTML code:
<button autoid="_n_j" type="button" class="_n_j2 o365button" aria-labelledby="_ariaId_31" regionbehavior="1">
<span class="_n_l2 owaimg ms-Icon--plus ms-bcl-tp ms-bg-transparent ms-icon-font-circle ms-fcl-tp ms-icon-font-size-20-circle" role="presentation"></span>
<span class="_n_k2 ms-font-weight-regular ms-font-color-themePrimary" id="_ariaId_31">New mail</span>
</button>
I am trying to press this using the following VBA code:
Dim objButton As Object
Set objButton = IE.Document.getElementById("_n_j2 o365button")
objButton.onfocus
objButton.onclick
But am getting a run time error. I think this is because the button is using javascript (page doesnt reload when pressed, just updates). Any ideas how to do this?