Visio) (Application.TemplatePaths 屬性

會取得或設定 Microsoft Visio 用來尋找範本的路徑。 讀取/寫入。

語法

運算式TemplatePaths

expression 代表 Application 物件的變數。

傳回值

字串

註解

TemplatePaths 屬性預設會設定為空字串 ("")。

傳遞至 TemplatePaths 屬性並從中接收的字串,與 [ 檔案位置 ] 對話方塊中顯示的字串相同。 (按一下 [檔案] 索引 標籤,依序按一下 [ 選項]、[ 進階],然後按一下 [一 ] 底下的 [ 檔案位置) 此字串會儲存在 HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Visio\Application\TemplatePath 子機碼中。

當 Visio 尋找範本時,它會在 TemplatePaths 屬性中指名的所有路徑以及這些路徑的所有子資料夾內搜尋。 如果您將 TemplatePaths 屬性傳遞給 EnumDirectories 方法,它便會傳回所傳入資料夾完整路徑的完整清單。

設定TemplatePaths屬性會取代 [檔案位置] 對話方塊中[範本] 的現有值。 若要保留現有的值,請取得現有的字串,然後將新的檔案路徑附加到該字串中,如下列程式碼所示:

Application.TemplatePaths = Application.TemplatePaths & ";" & "newpath".

警告

以任何方式修改 Windows 登錄,不論是在登錄編輯程式中還是以程式設計方式,都一律會有某種程度的風險。 不正確的修改會導致嚴重的問題,而可能需要重新安裝作業系統。 因此,較理想的做法是在每次修改電腦的登錄之前先行進行備份。

範例

這個 Microsoft Visual Basic for Applications (VBA) 宏會示範如何使用 TemplatePaths 屬性將路徑新增至 [範本 路徑] 方塊。

 
Public Sub TemplatePaths_Example()  
 
    Dim strMessage As String 
    Dim strNewPath As String 
    Dim strTemplatePath As String 
    Dim strTitle As String 
     
    'Get the path we want to add.  
    strTemplatePath = Application.TemplatePaths  
    strTitle = "TemplatePaths"  
    strMessage = "The current content of the Visio Templates path box is:"  
    strMessage = strMessage & vbCrLf & strTemplatePath  
    MsgBox strMessage, vbInformation + vbOKOnly, strTitle  
    strMessage = "Type in an additional path for Visio to look for templates."  
    strNewPath = InputBox$(strMessage, strTitle)  
 
    'Make sure the folder exists and that it's not 
    'already in the Templates path box.  
    strMessage = ""  
    If strNewPath = ""  Then 
        strMessage = "You did not enter a path." 
        ElseIf InStr(strTemplatePath, strNewPath)  Then 
            strMessage = "The path you specified is already in the Templates path box."  
        ElseIf Len(Dir$(strNewPath, vbDirectory)) = 0 And _  
                Len(Dir$(Application.Path & strNewPath, _  
                vbDirectory)) = 0 Then 
            strMessage = "The folder you typed does not exist (or is blank)."  
        Else 
            Application.TemplatePaths = strTemplatePath & ";" & strNewPath  
            strMessage = "We just added " & strNewPath & _  
                " to the Templates path box."  
    End If 
   
    If strMessage <> ""  Then 
        MsgBox strMessage, vbExclamation + vbOKOnly, strTitle  
    End If  
  
End Sub

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應