VBA - Click a checkbox within internet explorer using <input and class

  • Hello,


    I am trying to input the information from excel cells into a website and then click two buttons. I am stuck on the final step of clicking the last button.


    Here is my code:



    Here is the code from internet explorer:

    <input class="names" onclick="getname" type="checkbox">


    I am self taught and new to VBA. Any guidance would be greatly appreciated.


    Thank you!

    Edited once, last by pike: code tags ().

  • Below is what I am having issues with:

    'click to select the the checkbox

    :thumbdown: objIE.document.getElementsByClassName("names")(0).Click :thumbdown:


    :thumbdown:Message alerts me with:

    Run-time error '91'

    Object variable or With block variable not set. :thumbdown:


    End Sub


    Here is the code from internet explorer:

    <input class="names" onclick="getname" type="checkbox">


    I am self taught and new to VBA. Any guidance would be greatly appreciated.


    Thank you!


    Edit: objIE.document.getElementsByClassName("names")(0).Click

  • Try to loop for the correct id example below, worked for me when unable to directly click on the link / button.

    Code
    dim itm as object, itm1 as object
    set itm = objIE.document.getElementsByClassName("names")
    
    for each itm1 in itm
    debug.print itm1.id
    itm1.focus
    itm1.click
    next itm1

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!