返回 IHTMLElementCollection 集合,该集合代表当前文档中具有指定名称和/或 ID 属性的所有定位元素。定位元素对应于 <A> 标记。
expression.anchors
expression 必选。返回“应用于”列表中的对象之一的表达式。
此集合先按名称索引,再按标识符索引。如果发现相同的名称,则返回具有该名称的项目的集合。相同名称的集合随后必须按位置序号进行引用。
如果未设置 anchors 属性,则其不会出现在集合中。
下列示例返回当前文档中所有定位元素的集合并显示与每一元素相关联的名称。
Sub AnchorsCollection()
'Returns the collection of all anchor elements in the active document.
Dim objAll As IHTMLElementCollection
'Reference the anchors collection
Set objAll = FrontPage.ActiveDocument.anchors
For i = 0 To objAll.Length - 1
'Display names of all set anchor items in collection
MsgBox "Element name: " & objAll.Item(i).Name
Next i
End Sub