【发布时间】:2018-04-19 06:00:22
【问题描述】:
我想用属性名称(“charset”)获取标签(“meta”)的所有属性值。 作为我的宏的结果,我希望看到:
1/4 element "charset" = UTF-8
但我明白了:
1/2 element "charset" = UTF-82/2 element "charset" = UTF-8
我哪里做错了?
Option Explicit
Sub ParseAnAttr()
Dim MetaTags As String, i As Integer, j As Integer
MetaTags = ""
MetaTags = MetaTags & "<meta charset=""UTF-8""/> "
MetaTags = MetaTags & "<meta name=""ResourceLoaderDynamicStyles"" content=""1""/> "
MetaTags = MetaTags & "<script type=""text/javascript""> "
MetaTags = MetaTags & "<meta name=""generator"" content=""Media""/> "
MetaTags = MetaTags & "<meta name=""referrer"" content=""origin""/> "
Dim objHtml As Object
Set objHtml = CreateObject("htmlfile")
With objHtml
.Open
.write MetaTags
.Close
End With
Dim objElements As Object, objElement As Object
Set objElements = objHtml.getElementsByTagName("meta")
For Each objElement In objElements
If objElement > 0 Then i = i + 1
Next objElement
For Each objElement In objElements
For j = 0 To i - 1
If objElement.Charset <> "" Then
Debug.Print j + 1 & "/" & i & " element ""charset"" = " & objElement.Charset
End If
Next j
Next objElement
End Sub
【问题讨论】: