Interaction with button on webpage using excel vba working only in step debugging mode

PunitD

I am trying to fetch the data from website & put it in the excel worksheet

Scenario: Webpage contains button with id=btnAllRun.

When i click on the button,table is generated dynamically containing information in tr tags inside it. Using macro i need to count no. of the such tr tags & put the count in worksheet.

Code:

Dim IE as Object
Sub Button_Click()

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate URL
Do
    DoEvents
Loop Until IE.ReadyState = 4 //waiting for the webpage to load

Set Elmt = IE.Document.getElementById("btnAllRun") //get button elmt for All Running
Elmt.Click //Clicking button
Do
    DoEvents
Loop Until IE.ReadyState = 4

Set Tbl = IE.Document.getElementById("gvRunning") //gets table elmt containing tr tags
Sheets("XXX").Range("B36") = Tbl.Rows.Length - 1

When i am trying to run the macro i get 'Object Variable or with block not set' but when running the same macro in step debugging mode i get the correct results.

Any help on this would be greatly appreciated!!

Siddharth Rout

If it works in debug mode then it means your DoEvents is not working as expected. In such a case I use a customized routine Wait. So what I am doing is forcing the code to wait for a specific amount of time and then continue. For slower systems you may have to increase the time.

Wait 2 basically pauses the code for 2 seconds.

Try this. This has worked for me in many occasions.

Dim IE As Object

Sub Button_Click()
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.Navigate URL

    Do While IE.ReadyState <> 4: DoEvents: Loop

    Wait 2

    Set Elmt = IE.Document.getElementById("btnAllRun")

    Wait 2

    Elmt.Click

    Do While IE.ReadyState <> 4: DoEvents: Loop

    Wait 2

    Set Tbl = IE.Document.getElementById("gvRunning")

    Sheets("XXX").Range("B36") = Tbl.Rows.Length - 1

    '
    '~~> Rest of the code
    '
End Sub

Private Sub Wait(ByVal nSec As Long)
    nSec = nSec + Timer
    While nSec > Timer
        DoEvents
    Wend
End Sub

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Interaction with button on webpage using excel vba working only in step debugging mode

From Dev

how to click a button on webpage having class name using vba excel

From Dev

Export to Excel in datagridView is working only while debugging

From Dev

Press Button on Webpage with VBA

From Dev

Webpage Print button not working

From Dev

Disable button using Excel VBA

From Dev

Excel bracket using VBA not working?

From Java

Excel VBA Stops Working When I Add Step Event

From Dev

Press a button on a webpage using VBA and without opening IE

From Dev

HttpUrlConnection works only in debugging mode

From Dev

Changing Contents of Select tag on a webpage using excel vba (To download CSV files from the webpage)

From Dev

VBA code only working correct in debug.mode

From Dev

Find the only button that is enabled on a webpage

From Dev

Login to javascript webpage with Excel vba

From Dev

Debugging Using Arrays in VBA

From Dev

Excel 2016 VBA Workbooks.Open Loses Debug Step Mode.. revisited

From Dev

Text entered into Webpage Search Box via Excel VBA is not detected when clicking Search button

From Dev

EXCEL VBA Create an Interaction of two Arrays

From Dev

Qt debugging in release mode - all methods not working

From Dev

How do I auto-click a button on a webpage using only a URL?

From Dev

Refresh the webpage, while the webpage is not loaded properly in VBA excel

From Dev

microsoft excel vba copying data from webpage

From Dev

Excel VBA loop to input data in webpage

From Dev

Excel Vba (onclick button)

From Dev

VBA - Set Property in Subroutine to Automatically Step Over While Debugging

From Dev

VBA Debugging - step through main program, but run routines called from it?

From Dev

VBA - Set Property in Subroutine to Automatically Step Over While Debugging

From Dev

Update Button for user form using Excel-VBA

From Dev

Add dynamic form into excel on button click using VBA

Related Related

  1. 1

    Interaction with button on webpage using excel vba working only in step debugging mode

  2. 2

    how to click a button on webpage having class name using vba excel

  3. 3

    Export to Excel in datagridView is working only while debugging

  4. 4

    Press Button on Webpage with VBA

  5. 5

    Webpage Print button not working

  6. 6

    Disable button using Excel VBA

  7. 7

    Excel bracket using VBA not working?

  8. 8

    Excel VBA Stops Working When I Add Step Event

  9. 9

    Press a button on a webpage using VBA and without opening IE

  10. 10

    HttpUrlConnection works only in debugging mode

  11. 11

    Changing Contents of Select tag on a webpage using excel vba (To download CSV files from the webpage)

  12. 12

    VBA code only working correct in debug.mode

  13. 13

    Find the only button that is enabled on a webpage

  14. 14

    Login to javascript webpage with Excel vba

  15. 15

    Debugging Using Arrays in VBA

  16. 16

    Excel 2016 VBA Workbooks.Open Loses Debug Step Mode.. revisited

  17. 17

    Text entered into Webpage Search Box via Excel VBA is not detected when clicking Search button

  18. 18

    EXCEL VBA Create an Interaction of two Arrays

  19. 19

    Qt debugging in release mode - all methods not working

  20. 20

    How do I auto-click a button on a webpage using only a URL?

  21. 21

    Refresh the webpage, while the webpage is not loaded properly in VBA excel

  22. 22

    microsoft excel vba copying data from webpage

  23. 23

    Excel VBA loop to input data in webpage

  24. 24

    Excel Vba (onclick button)

  25. 25

    VBA - Set Property in Subroutine to Automatically Step Over While Debugging

  26. 26

    VBA Debugging - step through main program, but run routines called from it?

  27. 27

    VBA - Set Property in Subroutine to Automatically Step Over While Debugging

  28. 28

    Update Button for user form using Excel-VBA

  29. 29

    Add dynamic form into excel on button click using VBA

HotTag

Archive