3

I would like to use...

Dim IE As Object

Set IE = CreateObject("InternetExplorer.Application")

With appropriate code to check a checkbox on a webpage

Clipped Screen Shot of Checkbox

The HTML Code on the rendered page is...

<form class="form-inline" style="float:right">
    <div class="checkbox">
        <label style="padding-top: 1px">
            <input data-bind="checked: orderBook.showAll" style="top:2px"  
             type="checkbox" /> Show All
        </label>
    </div>
</form>

I can't use getElementsByID() as I don't think it has one.

Any suggestions?

C-Pound Guru
  • 15,967
  • 6
  • 46
  • 67

1 Answers1

1

While your checkbox does not have an ID, it does have a Class. Without seeing more of the HTML code I cannot be entirely sure, but the following code should allow you to set your checkbox to a variable:

Option Explicit

Sub test

    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.Application")

    ' Navigate to desired web page

    ' Code to ensure page is fully loaded

    Dim cBox As Object
    Set cBox = IE.document.getElementsByClassName("checkbox")(0)

End Sub

Then you can use cBox how you need to (possibly like cBox.Click or another method). Notice that I appended (0) to the end of that statement? That means you are assigning the first instance of that class to the variable. If this checkbox is the only object with the class name of checkbox, then this won't be an issue, but you may have to change this number if it's not.

K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
  • The code runs fine (with cBox.Click) but it does not tick the checkbox on the webpage. When checked manually, a DHTML table shows the maximum number of rows on the webpage. Probably not understanding the subject fully enough - any recommendations of good reference source for VBA using DOM? – Creative_Guy Jan 16 '18 at 18:14
  • Considering that I didn't have access to the full HTML code or a link to the source, it's impossible for me to determine the instance number of your checkbox. You can try changing the `(0)` to `(1)` or a few more up to see if that helps. Some checkboxes can work differently as well. You can try `cBox = True`, `cBox.Value = True` and see if that works as well. – K.Dᴀᴠɪs Jan 16 '18 at 18:30
  • Here is a link to the webpage in question... https://bittrex.com/Market/Index?MarketName=BTC-ETH – Creative_Guy Jan 16 '18 at 18:58