會傳回完整及選擇性規範化的超連結?對位址表示。
語法
expression。
CreateURL( _CanonicalForm_ )
表達 代表 Hyperlink 物件的變數。
參數
| 名稱 | 必要/選用 | 資料類型 | 描述 |
|---|---|---|---|
| CanonicalForm | 必要 | 整數 | 如果傳回標準格式,則為 True (非零),否則為 False (0) |
傳回值
字串
註解
Hyperlink 物件的 CreateURL 方法可根據超連結的基底位址解析 URL。
使用標準格式時,CreateURL 方法會對超連結套用 URL 規範化規則。 規範化期間,只有空格會保留在 URL 編碼中。 系統會假設 HTTP URL 都是使用連接埠 80,因此在規範化期間,會移除連接埠 80。 例如,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 取代為您電腦上的有效檔案路徑、以有效的因特網或內部網路位址取代 address ,並將 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 支援與意見反應。