Dick Plixen
Dick Plixen

Reputation: 71

VBA InStr to check HTML

Trying to check HTML for specific keywords using VBA function InStr but unfortunately it's not returning the correct results. Here's the VBA...

With IE
    .Visible = True
    .navigate my_url4
End With

Do Until Not IE.Busy And IE.readyState = 4
    DoEvents
Loop

promo = IE.Document.getElementsByTagName("td") 
Debug.Print promo
If InStr(promo, "C8") = 0 Then
    ActiveSheet.Range("C10") = "Not Found"
Else
    ActiveSheet.Range("C10") = "Found"
End If    

Here's the HTML that I'm trying to check for the value in cell C8...

<div style="overflow:auto; height=75%; scrollbar-face-color: #D6DFF7; scrollbar-track-color:white;">
<table border="1" width="100%" cellspacing="0" cellpadding="10" style="border-collapse: collapse" bordercolor="#111111">

    <tr>
        <td class='Header'>Customer History from  Monday, September 12, 2016 to Monday, October 10, 2016 </td> 
    </tr>

    <table border='1' width='100%' cellspacing='0' cellpadding='2'>
        <tr>
            <td class="Content" align="center" width="20%"><b>Promotion</b></td>
            <td class="Content" align="center" width="28%"><b>Issue Date</b></td>
        </tr>
    </table>                


    <table border='1' width='100%' cellspacing='0' cellpadding='2'>
    <tr>
        <td class='Content' width="20%"> October Offer  </td>
        <td class='Content' width="28%"> 10/10/2016 10:50:38 AM </td>
    </tr>
    </table>

    <table border='1' width='100%' cellspacing='0' cellpadding='2'>
    <tr>
        <td class='Content' width="20%"> Exclusive Online Promotion! </td>
        <td class='Content' width="28%"> 10/10/2016 10:50:32 AM </td>
    </tr>
    </table>

    <table border='1' width='100%' cellspacing='0' cellpadding='2'>
    <tr>
        <td class='Content' width="20%"> Exclusive October Offer  </td>
        <td class='Content' width="28%"> 10/10/2016 10:50:10 AM </td>
    </tr>
    </table>

No matter what I type into cell C8 I get the same result in C10 which leads me to believe something is wrong with the "promo" variable since the InStr always comes back 0.

Any insights would be appreciated.

Thank you

Upvotes: 0

Views: 529

Answers (1)

YowE3K
YowE3K

Reputation: 23974

If InStr(promo, "C8") = 0 Then is looking for the character string "C8" within the string variable promo. To look for the value of the cell C8, you need to say

If InStr(promo, ActiveSheet.Range("C8").Value) = 0 Then

Upvotes: 1

Related Questions