View Single Post
 
Old 02-16-2024, 03:25 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Susan,

We are not a code writing service. When you post here, the expectation is to tell us your requirement and show us what you have tried in pursuing that goal. That will quicken the day that you are helping others as well.


A quick internet search would reveal many examples of how to use VBA to select a folder path.


All that said, here is a more general bit of code for backing up a template (regardless of what the template name is:

Code:
Sub BackupTemplate()
Dim strFileName As String
Dim strFolderPath As String
  strFolderPath = fcnBackupFolderSelect
  If strFolderPath = vbNullString Then
    MsgBox "You have not selected a valid folder path.", vbInformation + vbOKOnly, "INVALID PATH"
    GoTo lbl_Exit:
  End If
  strFileName = Left(ThisDocument.Name, InStrRev(ThisDocument.Name, ".") - 1) & " BU"
  strFileName = strFileName & " " & Format(Now, "MM-dd-yyyy") & " Time stamp " & Format(Now, "hh-mm-ss")
  ThisDocument.Save
  ThisDocument.SaveAs2 FileName:=strFolderPath & "\" & strFileName & ".dotm", Addtorecentfiles:=False
  MsgBox "The template backup is saved as " & strFileName & ".dotm" & " at: " & strFolderPath, vbInformation + vbOKOnly, "Completed"
lbl_Exit:
  Exit Sub
End Sub

Function fcnBackupFolderSelect() As String
  fcnBackupFolderSelect = vbNullString
  With Application.FileDialog(msoFileDialogFolderPicker)
    If .Show = -1 Then
     fcnBackupFolderSelect = .SelectedItems(1)
    End If
  End With
lbl_Exit:
  Exit Function
End Function
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote