How to find document and template filenames


The GetPaths VBA macro reports the filenames for the Normal template, the base template, and the current document in ArcMap. The ITemplates::Item property is used to get this information.

How to use

  1. Paste this code into a module in the Visual Basic Editor for ArcMap.
  2. Run the GetPaths macro.
  3. A message box showing the filenames is displayed.
[VBA]
Public Sub GetPaths()
    Dim pTemplates As ITemplates
    Dim lTempCount As Long
    Dim strNormalPath As String
    Dim strBasePath As String
    Dim strDocPath As String
    
    Set pTemplates = Application.Templates
    lTempCount = pTemplates.Count
    
    ' Normal is always the first item
    strNormalPath = pTemplates.Item(0)
    
    ' The document is always the last item
    strDocPath = pTemplates.Item(lTempCount - 1)
    
    ' If present, the base template is the middle item
    If lTempCount = 3 Then
        strBasePath = pTemplates.Item(1)
    Else
        strBasePath = "NO BASE TEMPLATE LOADED"
    End If
    
    ' Report pathnames
    MsgBox "Normal Template:  " & strNormalPath & vbNewLine & _
        "Base Template:  " & strBasePath & vbNewLine & _
        "Document:  " & strDocPath
End Sub