Make vba wait till explorer is ready

345 views Asked by At

I have a code that pulls down table data from urls.

There I need to make vba to perform a clik action (to unhide last table), which gives back expected result only in debug mode.

Set objCollection = html.getElementsByClassName("{a keyword is entered here}")

objCollection(0).Click

If I simply run the code, it seems like click action was not performed.

If I stop code run right after click command and then let the code again to run, then I get back the expected result.

I have tried many things:

  • DoEvents
  • separate sub ("Refresh_All_Data_Connections") advised in some other topic

where issue was similar

Can somebody help to find the missing code part?

1

There are 1 answers

3
Deepak-MSFT On

Try to make a test with code below may help you to solve your issue.

Sub demo()
 Dim IE As InternetExplorer
    
    Set IE = CreateObject("InternetExplorer.Application")
       
    IE.navigate "C:\Users\Administrator\Desktop\demo66.html"
    
    IE.Visible = True
    
  While IE.Busy
        DoEvents
  Wend
    Do Until IE.readyState = READYSTATE_COMPLETE
        DoEvents
    Loop
    Do Until IE.document.readyState = "complete"
        DoEvents
    Loop
    
   Set Button = IE.document.getElementById("btn1")
    Button.Click
    
   
End Sub

You need to change the URL and button ID in above code. Further you can modify the code as per your requirements.

Also check that scripts are already allowed and IE not showing any prompt to allow it. It can suppress the click.