0

I get the error in the title above when trying to execute a VBA command to click a button on Internet Explorer 11:

Const sURL As String = "MY_URL"
    
Set ie = New InternetExplorerMedium
    
With ie
    .Visible = True
    .Navigate sURL
    While .Busy Or .ReadyState < 4: DoEvents: Wend
    .Document.getElementById("ctl00_contentPH_btnCopyTimesheet").Click '***HERE***
    While .Busy Or .ReadyState < 4: DoEvents: Wend
End With
3
  • There's no element with that id in the document when your code runs. Try adding a breakpoint and waiting a few seconds before continuing: if it works then there's a timing problem (maybe the button is created dynamically at some point after the page is done loading) Commented Nov 18, 2020 at 5:03
  • I agree with the suggestion given by the TimWilliams. I tested the code on my side with the button that has ID: ctl00_contentPH_btnCopyTimesheet. I found that the code is working fine on my side. See test result here. So it can be possible that the button is not available with this ID causing this error. So you can check whether you are referring to the correct button or try to wait for some time before clicking the button. If the issue persists then please try to provide more info. and try to post the HTML code for that button may help to test the issue again. Commented Nov 18, 2020 at 5:55
  • Also try to avoid clicking button if possible. Look at where the button is taking you and navigate to that url directly (you might need to add some parameters to the url) Commented Nov 18, 2020 at 7:38

0