[英]VBA InStr to check HTML
尝试使用VBA函数InStr来检查HTML中的特定关键字,但不幸的是,它没有返回正确的结果。 这是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
这是我要检查的单元格C8中的值的HTML ...
<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>
无论我在C8单元格中键入什么内容,我都在C10中得到相同的结果,这使我相信“ promo”变量有问题,因为InStr总是返回0。
任何见解将不胜感激。
谢谢
If InStr(promo, "C8") = 0 Then
则在字符串变量promo
寻找字符串“ C8”。 要查找单元格C8的值,您需要说
If InStr(promo, ActiveSheet.Range("C8").Value) = 0 Then
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.