Redo of VBA, Web automation tick box in nested tables

riley2013

New Member
Joined
Apr 16, 2013
Messages
4
Apologies for last post hopefully a admin has removed the page..
Php code tags seems to be the only tags that work???

Hello All
First of all i would like to say this site is brilliant i have learnt so much already :)

Im in need of a solution to a very specific problem.

Ok my situation so far i have a rather large program in vba that accesses a site (confidential info im afriad will post snippets though) logs in navigates through a rabbit warren of pages using different types div's form's a href's etc and finally get to one page before where i need to extract information from!!

My problem.

this webpage has one large table then nested tables within for each entry.
for example
PHP:
<table><tr><td><table>info....</table></tr></td><tr><td><table>info....</table></tr></td><tr><td><table>info....</table></tr></td></table>
i need to find a way to search the data cells within the nested tables find a specific displayed value then if required tick the checkbox (which has dynamically genereated id's names etc) in that row then move on to the next table and do the same.

Wracking my brain with this one...

all i need to do is establish that one row has the data value i need and tick the check box that correlates (which is in the same row)

PHP:
<table border="0" cellpadding="0" cellspacing="0">              <tr class="altline">                <td>                  <table>                    <tr>                      <td class="col_time" title="16/04/2013">18:30</td>                      <td class="col_duration">00:51</td>                      <td class="col_placetype"></td>                      <td class="col_place">***data i need to check against parameters***</td>                      <td class="col_alerts"> </td>                      <td class="col_action"> </td>                      <td class="col_select">***Tick box i need checking if data matchs***<input type="checkbox" id="chkactualid" name="chkactualid" *******="chkactualid_*******()" value="chk25262717idl"></td>                    </tr>                  </table>                </td>              </tr>              <tr>                <td>                  <table>                    <tr>                      <td class="col_time" title="16/04/2013">17:37</td>                      <td class="col_duration">00:53</td>                      <td class="col_placetype">Restricted place</td>                      <td class="col_place">***data i need to check against parameters***</td>                      <td class="col_alerts"> </td>                      <td class="col_action"> </td>                      <td class="col_select">***Tick box i need checking if data matchs***<input type="checkbox" id="chkactualid" name="chkactualid" *******="chkactualid_*******()" value="chk37764453idv"></td>                    </tr>                  </table>                </td>              </tr>              <tr class="altline">                <td>                  <table>                    <tr>                      <td class="col_time" title="16/04/2013">17:01</td>                      <td class="col_duration">00:36</td>                      <td class="col_placetype"></td>                     <td class="col_place">***data i need to check against parameters***</td>                      <td class="col_alerts"> </td>                      <td class="col_action"> </td>                      <td class="col_select">***Tick box i need checking if data matchs***<input type="checkbox" id="chkactualid" name="chkactualid" *******="chkactualid_*******()" value="chk25262043idl"></td>
                    </tr>                 </table></table>

 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
It helps if you indent the HTML and put line breaks in so we can see its structure, like this:
HTML:
<table border="0" cellpadding="0" cellspacing="0">              
  <tr class="altline">                
    <td>
      <table>
        <tr>
          <td class="col_time" title="16/04/2013">18:30</td>
          <td class="col_duration">00:51</td>
          <td class="col_placetype"></td>
          <td class="col_place">***data i need to check against parameters***</td>
          <td class="col_alerts"> </td>
          <td class="col_action"> </td>
          <td class="col_select">***Tick box i need checking if data matchs***
            <input type="checkbox" id="chkactualid" name="chkactualid" *******="chkactualid_*******()" value="chk25262717idl">
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table>
        <tr>
          <td class="col_time" title="16/04/2013">17:37</td>
          <td class="col_duration">00:53</td>
          <td class="col_placetype">Restricted place</td>
          <td class="col_place">***data i need to check against parameters***</td>
          <td class="col_alerts"> </td>
          <td class="col_action"> </td>
          <td class="col_select">***Tick box i need checking if data matches***
            <input type="checkbox" id="chkactualid" name="chkactualid" *******="chkactualid_*******()" value="chk37764453idv">
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr class="altline">
    <td>
      <table>
        <tr>
          <td class="col_time" title="16/04/2013">17:01</td>
          <td class="col_duration">00:36</td>
          <td class="col_placetype"></td>
          <td class="col_place">***data i need to check against parameters***</td>
          <td class="col_alerts"> </td>
          <td class="col_action"> </td>
          <td class="col_select">***Tick box i need checking if data matches***
            <input type="checkbox" id="chkactualid" name="chkactualid" *******="chkactualid_*******()" value="chk25262043idl">
          </td>
        </tr>
      </table>
    </table>
If you have IE9, you could use GetElementsByClassName like this:
Code:
Sub x()
    Dim HTMLdoc As HTMLdocument
    Dim TDs As IHTMLElementCollection, TD As HTMLTableCell
    Dim inpCB As HTMLInputElement
    Set TDs = HTMLdoc.getElementsByClassName("col_place")
    For Each TD In TDs
        If TD.innerText = "The data" Then
            Set inpCB = TD.parentElement.getElementsByTagName("INPUT")(0)  'get input element in parent row
            inpCB.Value = True  'tick box
        End If
    Next
End Sub
I don't have IE9 so can't test the above. For IE8, you could do something similar using .getElementsByTagName("TD") and loop through the collection of TD elements looking for TD.className = "col_place" and use the same If TD.innerText code block from there.
 
Upvote 0
thanks for that code display the code I copied did have the indents etc but for some reason it didn't like it

Unfortunatly i dont have ie9,

I think the key code there was

Set inpcB = TD.parentElement.getElementsByTagName("INPUT")(0)

I get the set part and see the .parentelement is the part im missing but I don't understand the (0) part...

Again thanks
 
Upvote 0
(0) returns the first item in the collection of INPUT elements.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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