我将一个变量声明为HTMLAnchorElement对象,该对象是为html“a”标签保留的。然后我将变量设置为段落标记,该标记应仅适用于HTMLParaElement对象。不管怎样,变量变成了一个副元素,尽管另有声明。
Option Explicit
'Turn on references to Microsoft Internet Controls
'and Microsoft HTML Object Libraries before running
Sub qstn()
Dim IE As New InternetExplorer
Dim el As HTMLAnchorElement
IE.navigate "www.youtube.com"
IE.Visible = True
Do Until IE.ReadyState = 4: Loop
Set el = IE.Document.getElementsByTagName("p")(0)
MsgBox TypeName(el)
End Sub