Hyperlink.CreateURL 方法 (Visio)

返回超链接绝对地址的完全限定的、以可选方式规范化的表示形式。

语法

expressionCreateURL( _CanonicalForm_ )

表达 一个代表 Hyperlink 对象的变量。

参数

名称 必需/可选 数据类型 说明
CanonicalForm 必需 Integer 如果采用规范形式,则为 True(非零值);否则为 False (0)。

返回值

String

备注

可以使用 Hyperlink 对象的 CreateURL 方法根据超链接的基本地址来解析相对 URL。

使用规范形式时,CreateURL 方法将对超链接应用 URL 规范化规则。 规范化期间仅对空格执行 URL 编码。 假定端口 80 与 HTTP URL 对应,且在规范化期间被删除。 例如,URL“https://www.microsoft.com:80/"返回为“https://www.microsoft.com/",而 https://www.microsoft.com:1000/" 保持不变。

示例

以下是 CreateURL 方法结果的一些示例:

Address = "https://www.microsoft.com/" 
CreateURL(False) returns "https://www.microsoft.com/" 
 
Address = "C:\My Documents\Spreadsheet.XLS" 
CreateURL(False) returns "file://C:\My Documents\Spreadsheet.XLS" 
CreateURL(True) returns "file://C:\My%20Documents\Spreadsheet.XLS" 
 

相对路径示例:

Assume : Document.HyperlinkBase = "https://www.microsoft.com/widgets/" 
Address = "../file.htm" 
CreateURL(False) returns "https://www.microsoft.com/file.htm" 
 

下面的示例说明如何使用 CreateURL 方法根据超链接的基本地址解析相对 URL。 运行此宏之前,请将 drive\folder\subfolder 替换为计算机上的有效文件路径,将 地址 替换为有效的 Internet 或 Intranet 地址,并将 drawing.vsd 替换为计算机上的有效文件。

 
Sub CreateURL_Example() 
 
 Dim vsoShape As Visio.Shape 
 Dim vsoHyperlink As Visio.Hyperlink 
 
 'Draw a rectangle shape on the active page 
 Set vsoShape = ActivePage.DrawRectangle(1, 2, 2, 1) 
 
 'Add a hyperlink to a shape 
 Set vsoHyperlink = vsoShape.AddHyperlink 
 
 'Allow relative hyperlink addresses 
 ActiveDocument.HyperlinkBase = "drive :\folder \subfolder " 
 
 'Return a relative address 
 vsoHyperlink.Address = "..\drawing.vsd " 
 
 'Print the resulting URLs to the Debug window 
 'to show how the relative path is derived 
 'from the base path and the difference 
 'between canonical and non-canonical forms 
 Debug.Print vsoHyperlink.CreateURL(False) 
 Debug.Print vsoHyperlink.CreateURL(True) 
 
 'Return an absolute address 
 vsoHyperlink.Address = "https://address " 
 
 'Print the resulting URL to the Debug window 
 Debug.Print vsoHyperlink.CreateURL(False) 
 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。