Excel VBA ( IF ) And Web Select or Click on Checkbox

drd0s

New Member
Joined
Apr 1, 2013
Messages
2
I would like to compare 2 values and click the checkbox inside the Tr element but for now i have:
Code:
Public Sub Worksheet_SelectionChange(ByVal Target As Range)
   
        EventSelect.Caption = ActiveCell.Value
        IpSource.Caption = Cells(ActiveCell.Row, ActiveCell.Column + 1)
        DestinationIP.Caption = Cells(ActiveCell.Row, ActiveCell.Column + 2)
       
End Sub
 
Sub Extract_TR_text()
 
    Dim URL As String
    Dim IE As InternetExplorer
    Dim HTMLdoc As HTMLDocument
    Dim TRelements As IHTMLElementCollection
    Dim TRelement As HTMLTableCell
    Dim Chkb0x As IHTMLElementCollection
 
   
    URL = "localhost/events/index.cgi"
 
    Set IE = New InternetExplorer
 
    With IE
        .navigate URL
        .Visible = True
 
      
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
 
        Set HTMLdoc = .document
    End With
 
    Set TRelements = HTMLdoc.getElementsByTagName("TR")
 
 
   
    For Each TRelement In TRelements
       
                
                
                MsgBox TRelement.innerText
               
                                
    Next
  IE.Quit
Set IE = Nothing
End Sub
Well after this what i have to say is ,
i want to compare the value on the TRelement with the EventSelect.Caption
.

In the
first part i would like to just msg box the TRelement.innerText if it is equal to the string in EventSelect.Caption.
And in the
2 part maybe if possible , search in the TR.Element and press the checkbox (checkbox.Select or Click)there is only 1 checkbox per TR.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
It's almost impossible to help without seeing the HTML, or better still being able to access the web site, but I see you're accessing localhost so maybe that isn't possible. And what type of checkbox are you talking about? Is it a normal HTML web form checkbox, i.e. < input type="checkbox" ?

One thing wrong is that the TR tag is a table row, not a table cell, so the Dim should be:
Code:
Dim TRelement As HTMLTableRow
And you might need to loop through each table cell (TD tags) in each table row, so:
Code:
Dim TD As HTMLTableCell
For Each TRelement In TRelements
   For Each TD In TRelement.Cells
        MsgBox TD.innerText
   Next                       
Next
To select (tick) a checkbox it's: theCheckBox.Checked = True, where theCheckBox is a reference to the checkbox element.

Also, where are you calling Extract_TR_text?
 
Upvote 0
It's almost impossible to help without seeing the HTML, or better still being able to access the web site, but I see you're accessing localhost so maybe that isn't possible. And what type of checkbox are you talking about? Is it a normal HTML web form checkbox, i.e. < input type="checkbox" ?

One thing wrong is that the TR tag is a table row, not a table cell, so the Dim should be:
Code:
Dim TRelement As HTMLTableRow
And you might need to loop through each table cell (TD tags) in each table row, so:
Code:
Dim TD As HTMLTableCell
For Each TRelement In TRelements
   For Each TD In TRelement.Cells
        MsgBox TD.innerText
   Next                       
Next
To select (tick) a checkbox it's: theCheckBox.Checked = True, where theCheckBox is a reference to the checkbox element.

Also, where are you calling Extract_TR_text?





Well first of all thnx for the quick reply , hm about the c0de i will send you know but in images by here but can you tell me how can i make something like this :

Code:
For Each TRelement In TRelements
    If Trelement.innerText = EventSelect.caption Then
        MsgBox TrElement.innerText
    End If
Next


...


and now the HTML c0de:

http://i78.photobucket.com/albums/j92/drdos/image001_zps6f59c155.jpg
http://i78.photobucket.com/albums/j92/drdos/2-5_zps3c99b9d0.jpg
 
Upvote 0
Firstly, please don't quote whole posts when replying. It just adds clutter.

how can i make something like this :

Code:
For Each TRelement In TRelements
    If Trelement.innerText = EventSelect.caption Then
        MsgBox TrElement.innerText
    End If
Next
That should work. Maybe you need Trim(Trelement.innerText) to remove leading and trailing spaces. And what do you mean 'make something like this'?

Posting HTML code in images isn't very useful because I can't easily copy and paste it. Just post the HTML in this thread between [ HTML] and [ /HTML] tags (without the spaces I've had to include).
 
Upvote 0

Forum statistics

Threads
1,215,891
Messages
6,127,602
Members
449,388
Latest member
macca_18380

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