使用“”无法正常工作检查字符串变量是否为空

时间:2016-01-25 15:19:23

标签: html string vba tags

快速提问,我有这段代码:

Sub Macro1()
Dim h As String
Dim browserIE As Object, ws As Worksheet
Set browserIE = CreateObject("InternetExplorer.Application")
browserIE.Top = 0
browserIE.Left = 800
browserIE.Width = 800
browserIE.Height = 1200
browserIE.Visible = True
Set ws = ThisWorkbook.Worksheets("Sheet1")

browserIE.navigate ("http://finder.fi/Televiestint%C3%A4laitteita+ja+palveluja/Nokia+Oyj/ESPOO/taloustiedot/159843")
Do While browserIE.ReadyState <> 4 And browserIE.Busy: DoEvents: Loop
Application.Wait (Now + TimeValue("0:00:3"))

x = 32

h = browserIE.document.body.getElementsByTagName("td")(x).innerText

Debug.Print " this is the element: " & h
If h = "" Then Debug.Print "there is no td tag when x=31"

End Sub

我想知道网站上有多少标签,我想我会使用while循环,一直增加x,直到它不再返回任何内容。要检查是否有任何返回,我将h变量指定为一个字符串,但是当检查它是否确实包含一个字符串时。但是,当我尝试这样做时,当前代码不具体工作:

 If h = "" Then Debug.Print "there is no td tag when x=31"

我也尝试过:

If len(h) = 0 then debug.print "there is no td tag when x=31"

但这不起作用,这使我相信问题是

h = browserIE.document.body.getElementsByTagName("td")(x).innerText 

0 个答案:

没有答案