返回 IHTMLElementCollection 集合,该集合代表当前文档中所有链接的集合。
expression.links
expression 必选。返回 DispFPHTMLDocument 对象的表达式。
此集合先按名称索引,再按标识符索引。如果发现相同的名称,则返回具有该名称的项目的集合。相同名称的集合随后必须按位置序号进行引用。
下列示例返回文档中所有链接的集合,并显示集合中链接的数目。
Sub ReturnLinks()
'Returns the collection of all links in the document
Dim objApp As FrontPage.Application
Dim objLinks As IHTMLElementCollection
Set objApp = FrontPage.Application
Set objLinks = objApp.ActiveDocument.links
'If not 0 links exist in the document
If Not objLinks.Length = 0 Then
'If only one link exists
If objLinks.Length = 1 Then
MsgBox "There is only one link in the collection."
'If more than one link exists
ElseIf objLinks.Length > 1 Then
MsgBox "There are " & objLinks.Length & _
" hyperlinks in the current document."
End If
Else
'Otherwise display message to user.
MsgBox "There are no links in the collection."
End If
End Sub