Question

Is it possible to write an If...Then command to reference a keyword/phrase in part of an HTML's innertext.

For example I'm looking to run an 'If...Then' command that will find a tag with part of the innertext including the phrase "Records Found.". Only one tag will have this phrase in its innertext if the tag exists. If this tag exists I want a cell in my worksheet to display 'Multiple Records Found'

    Dim ErrLi As Object
    Dim ErrObj As Object
    Dim x As Integer

    Set ErrLi = IE.Document.GetElementById("DivCenterTopArea").GetElementsByTagName("li")

    If Not ErrLi Is Nothing Then
      For x = 1 To ErrLi.Length - 1
        If ErrObj.innertext = & "records found." Then
          Range("Q" & (ActiveCell.Row)) = "Multiple Records Found"
        End If
      Next
    End If
Was it helpful?

Solution

Use the instr function

If instr(1, ErrObj.innertext, "records found.") > 0 Then
      Range("Q" & (ActiveCell.Row)) = "Multiple Records Found"
End If
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top