VBA Code to click a button on a VBA page

Mike UK

New Member
Joined
Dec 14, 2011
Messages
41
Hi.
I am trying to use my VBA code to click a button on an IE Web page. I have tried various lines of code but keep getting the Object Error 424.

Below is the web page code detailing the button....

HTML:
<td id="cellInvestment </br>Choice" align="left" name="cellInvestment </br>Choice" class="wizardNavSelected"

                     onclick = "return wizard_move('/Admin/ModelPortfolios/InvestmentChoice.aspx','');"

                    style="CURSOR: pointer;">

                    <span class="roundSelected"></span>

                    <span class = "WizardNavNumber">2. </span>Investment </br>Choice

                </td>


The VBA code I have tried includes:
VBA Code:
    Set btn = ie.document.getElementById("cellInvestment")
    btn.Click

ie.document.querySelector("button[type=submit]").click

The macro code looks like:
Sub Macro3()
Dim a As String
    Set App = CreateObject("InternetExplorer.Application")
    'Creates IE Webpage
    With App
        .Visible = True
        .Navigate "[URL]https://HIDDEN[/URL]"
        Do Until .ReadyState = 4
            DoEvents
        Loop
    End With
   
    Set btn = ie.document.getElementById("cellInvestment")
    btn.Click

Any help greatfully received.
 
Last edited by a moderator:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Were you able to solve this one?
Hi Worf,
Yes thank you.... I used this....
VBA Code:
Set app = CreateObject("InternetExplorer.Application")

                    With app
                        .Visible = True
                        .document.getElementById("cellInvestment </br>Choice").Click
                    End With

             Application.CutCopyMode = False                                            'Clears the Clipboard ready to copy the webpage
             Application.Wait (Now + TimeValue(DelaySec))

Though I had to put a timed loop in post the click to allow the table to load post clicking the button as the ReadyState = 4 didn't seem to work.

Thank you for taking the time to check.
 
Last edited by a moderator:
Upvote 0
Solution

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,078
Latest member
skydd

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top