FollowHyperlink 方法

expandtri全部显示

FollowHyperlink 方法可打开由超链接地址指定的文档或网页。

expression.FollowHyperlink(Address, SubAddress, NewWindow, AddHistory, ExtraInfo, Method, HeaderInfo)

expression    必需。返回“应用于”列表中的一个对象的表达式。

Address     必需,String 型。确定有效超链接地址的字符串表达式

SubAddress     可选,String 型。字符串表达式,用于确定由 address   参数指定的文档中的命名位置。默认值为空字符串 (" ")。

NewWindow     可选,Boolean 型。Boolean 值,该值为 True (–1) 时,将在新窗口中打开文档;该值为 False (0) 时,则在当前窗口中打开文档。默认值为 False

AddHistory     可选,Boolean 型。Boolean 值,该值为 True 时,将添加指向“历史记录”文件夹的超链接,该值为 False 时,则不添加指向“历史记录”文件夹的超链接。默认值为 True

ExtraInfo     可选,Variant 型。字符串Byte 数据数组,用于指定定位到超链接的其他信息。例如,该参数可以用来为 .ASP 或 .IDC 文件指定搜索参数。在 Web 浏览器中,extrainfo   参数可能出现在超链接地址后,并用问号 (?) 与地址分开。指定 extrainfo 参数时,不包括问号。

Method   可选 MsoExtraInfoMethodInteger 值,用于指定 extrainfo   参数的附加方式。method 参数可以是下列固有常量之一。

MsoExtraInfoMethod 可以是这些 MsoExtraInfoMethod 常量之一。

msoMethodGet default。extrainfo 参数将附加到超链接地址且只能是字符串。在默认情况下将传递该值。

msoMethodPost。extrainfo 参数作为字符串或 Byte 数据类型的数组传递。

HeaderInfo     可选 String 型。 用于指定页眉信息的字符串。默认情况下,headerinfo   参数是空字符串。

说明

通过使用 FollowHyperlink 方法,可以跟随一个不存在于控件中的超链接。该超链接可以由您或其他用户提供。例如,可以提示用户在对话框中输入超链接地址,然后使用 FollowHyperlink 方法来跟随该超链接。

浏览到某个超链接时,可以使用 extrainfo 和 method 参数来提供其他信息。例如,可以为搜索引擎提供参数。

可以使用 Follow 方法来跟随与控件相关联的超链接。

示例

下列函数提示用户输入一个超链接地址,然后跟随该超链接:

Function GetUserAddress() As Boolean

    Dim strInput As String

    On Error GoTo Error_GetUserAddress

    strInput = InputBox("Enter a valid address")

    Application.FollowHyperlink strInput, , True

    GetUserAddress = True

Exit_GetUserAddress:

    Exit Function

Error_GetUserAddress:

    MsgBox Err & ": " & Err.Description

    GetUserAddress = False

    Resume Exit_GetUserAddress

End Function

可以用以下的过程来调用该函数:

Sub CallGetUserAddress()

    If GetUserAddress = True Then

        MsgBox "Successfully followed hyperlink."

    Else

        MsgBox "Could not follow hyperlink."

    End If

End Sub