anchors Property
Returns an IHTMLElementCollection object that represents all of the bookmarks in a document. Bookmarks are <A> tags that have an associated name attribute.
expression.anchors
*expression * Required. An expression that returns one of the objects in the Applies To list.
Remarks
The anchors property returns only bookmarks, which are <A> tags that have the **name****attribute. Use the links property to return a collection of hyperlinks, which are <A> tags that have the href attribute.
Example
The following example returns an array of strings that represent the names of bookmarks in the specified document.
Function GetBookmarks(objDoc As FPHTMLDocument) As String()
Dim objAnchors As IHTMLElementCollection
Dim objAnchor As FPHTMLAnchorElement
Dim intCount As Integer
Dim strBookmarks() As String
Set objAnchors = objDoc.anchors
ReDim strBookmarks(objAnchors.Length - 1)
For intCount = 0 To objAnchors.Length - 1
Set objAnchor = objAnchors.Item(intCount)
If objAnchor.Name <> "" Then
strBookmarks(intCount) = objAnchor.Name
Else
strBookmarks(intCount) = objAnchor.Id
End If
Next
GetBookmarks = strBookmarks
End Function
Use the following code to call the preceding subroutine.
Sub CallGetBookmarks()
Dim strBookmarks() As String
Dim strBookmark As String
Dim intCount As Integer
On Error Resume Next
strBookmarks = GetBookmarks(ActiveDocument)
For intCount = 0 To UBound(strBookmarks)
strBookmark = strBookmark & strBookmarks(intCount) & vbCrLf
Next
MsgBox strBookmark
End Sub
Applies to | FPHTMLDocument Object | IHTMLDocument2 Object