vba Default Storage Location for New Templates

User avatar
Charles Kenyon
5StarLounger
Posts: 626
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

vba Default Storage Location for New Templates

Post by Charles Kenyon »

With Office 2013, Microsoft added another Templates location, the default storage location for new templates. This is set under Options:Save instead of Options:Advanced:File Locations. This is discussed in my page on the FileNew Dialog: https://www.addbalance.com/usersguide/fileNew.htm

I have the following macro I wrote back in 2001 which addresses locations set under Options:Advanced:File Locations. I would like to add the default save location for new templates but do not know where to find that setting using vba.

Code: Select all

Sub TemplatesPathIsMacro()
    '
    ' TemplatesPathIsMacro Macro
    ' Macro written 3 December 2001 by Charles Kyle Kenyon
    '  modified 4 January 2024 to add documents location
    '
    Dim sUserTemplatesLocation As String
    Dim sWorkgroupTemplatesLocation As String
    Dim sStartUpTemplatesLocation As String
    ' Dim sNewTemplatesLocation As String
    Dim sDocumentsDefaultLocation As String
    Dim sActiveDocumentPath As String
    '
    sUserTemplatesLocation = Options.DefaultFilePath(wdUserTemplatesPath) & "\"
    sWorkgroupTemplatesLocation = Options.DefaultFilePath(wdWorkgroupTemplatesPath) & "\"
    sStartUpTemplatesLocation = Options.DefaultFilePath(wdStartupPath) & "\"
    ' sNewTemplatesLocation = Options.DefaultFilePath ' nothing here to match
    sDocumentsDefaultLocation = Options.DefaultFilePath(wdDocumentsPath) & "\"
    If ActiveDocument.Path <> "" Then
        sActiveDocumentPath = "The active document's save path is: " & ActiveDocument.Path & "\"
    Else
        sActiveDocumentPath = "This document has never been saved!"
    End If
    '
    MsgBox Prompt:="The user templates are in:" & vbCrLf _
                   & sUserTemplatesLocation & vbCrLf & vbCrLf _
                   & "The Workgroup Templates are in:" & vbCrLf _
                   & sWorkgroupTemplatesLocation & vbCrLf & vbCrLf _
                   & "The Startup (Add-In) Templates are in:" & vbCrLf _
                   & sStartUpTemplatesLocation & vbCrLf & vbCrLf _
                   & "The default save location for documents is: " & sDocumentsDefaultLocation & vbCrLf _
                   & vbTab & "Note: this may have been temporarily changed by a save." & vbCrLf & vbCrLf _
                   & sActiveDocumentPath, _
           Buttons:=vbInformation, title:="Default file location settings"
End Sub
Last edited by Charles Kenyon on 04 Jan 2024, 17:37, edited 1 time in total.

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: vba Default Storage Location for New Templates

Post by HansV »

As far as I know it is not directly exposed in Word VBA, but you can retrieve it from the Windows registry. That won't work on Mac, obviously.

Code: Select all

    Dim sTemplateSaveLocation As String
    sTemplateSaveLocation = CreateObject("WScript.Shell").RegRead _
        ("HKEY_CURRENT_USER\Software\Microsoft\Office\" & Application.Version & "\Word\Options\PersonalTemplates")
Best wishes,
Hans

snb
4StarLounger
Posts: 586
Joined: 14 Nov 2012, 16:06

Re: vba Default Storage Location for New Templates

Post by snb »

Why not using With ... End With ?
Why so many variables that do not vary ?

Code: Select all

Sub M_snb()
  With Options
    MsgBox "User templates" & vbTab & vbTab & .DefaultFilePath(2) & vbLf _
      & "Workgroup Templates" & vbTab & .DefaultFilePath(3) & vbLf _
      & "Startup Templates" & vbTab & vbTab & .DefaultFilePath(8) & vbLf _
      & "Default save location" & vbTab & .DefaultFilePath(0), , "File location settings"
  End With
End Sub

User avatar
Charles Kenyon
5StarLounger
Posts: 626
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: vba Default Storage Location for New Templates

Post by Charles Kenyon »

Because I wrote that 20 years ago and was lazy!