Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-15-2024, 11:36 AM
RRB's Avatar
RRB RRB is offline Revised Macro to backuo the normal.dotm Windows 11 Revised Macro to backuo the normal.dotm Office 2021
Susan Flamingo
Revised Macro to backuo the normal.dotm
 
Join Date: May 2014
Location: The Holy City of Jerusalem
Posts: 263
RRB is on a distinguished road
Default Revised Macro to backuo the normal.dotm

Forum member Charles Kenyon has written a macro that backs up the normal.dotm template. See below.

Could someone revise it so it asks where to place the backup and saves it there, appending the date as it does now?

Thank you and have a good day!

Susan Flamingo
------------------------------------------------>
Sub BackUpNormalTemplate()



' Run to Backup Normal template to dated backup
' Charles Kenyon 10 Jan 2020
' Backup Normal Template Macro
' Appends date to "Normal Backup" when saving, saves in special folder,
' then returns save path to current - thanks to Jay Freedman for that
' This code must be in the Normal template to work - not in another global

'
On Error Resume Next
Dim strName As String
Dim intLenPath As Integer ' length of path to templates folder without name of folder
Dim strPath As String 'Holder for current path
Dim strStorePath As String
'
Let intLenPath = InStrRev(Application.Options.DefaultFilePath(wdUse rTemplatesPath), "")
Let strStorePath = Left(Application.Options.DefaultFilePath(wdUserTem platesPath), intLenPath)
Let strStorePath = strStorePath & "Normal Backups"
'
' Check if folder exists, if not, create it
If Dir(strStorePath) = vbNullString Then MkDir (strStorePath)
'
Let strPath = Application.Options.DefaultFilePath(wdDocumentsPat h)
Let strName = "Normal Backup"
' add date & Time
Let strName = strName & " " & Format((Year(Now() + 1) Mod 100), "20##") & "-" & _
Format((Month(Now() + 1) Mod 100), "0#") & "-" & _
Format((Day(Now()) Mod 100), "0#") & "-" & _
Format(Now(), "HH_mm") 'add date & time
'
' Do the save
' MsgBox strStorePath & strName & ".dotm"
ThisDocument.Save 'save normal template (code holder) itself
ThisDocument.SaveAs2 FileName:=strStorePath & "" & strName & ".dotm", Addtorecentfiles:=False
' Reset save path
Let Application.Options.DefaultFilePath(wdDocumentsPat h) = strPath
'
' reset error message
MsgBox "The Normal.dotm template was saved as " & strName & ".dotm" & vbCr & vbLf & " in the folder: " & strStorePath, Title:="Completed", Buttons:=vbOKOnly
'
On Error GoTo -1
End Sub

<------------------------------------------------------------------------
Reply With Quote
  #2  
Old 02-16-2024, 03:25 AM
gmaxey gmaxey is offline Revised Macro to backuo the normal.dotm Windows 10 Revised Macro to backuo the normal.dotm Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
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
  #3  
Old 02-16-2024, 03:58 AM
RRB's Avatar
RRB RRB is offline Revised Macro to backuo the normal.dotm Windows 11 Revised Macro to backuo the normal.dotm Office 2021
Susan Flamingo
Revised Macro to backuo the normal.dotm
 
Join Date: May 2014
Location: The Holy City of Jerusalem
Posts: 263
RRB is on a distinguished road
Default Revised Macro to backuo the normal.dotm

Quote:
Originally Posted by gmaxey View Post
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
>>That will quicken the day that you are helping others as well.

I doubt I ever will be anywhere near the expertise of other members of this group. I am also terrified to make unqualified suggestions that could potentially ruin someone's work day.

Usually, my first move is to ask Dr. Google. And only then leave a request for help here. But I thought that for experts like you, this is a 2-minute story and for me, it could occupy a full day

I will try to be more independent in the future.

Thank you and have a good day!

Susan Flamingo
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Normal.dotm reset messgchr Word 2 07-19-2020 03:53 PM
Revised Macro to backuo the normal.dotm macro not saved in normal.dotm silveredge8181 Word 8 06-09-2014 07:58 PM
Revised Macro to backuo the normal.dotm Adding macro to normal.dotm programmatically etippelt Word VBA 6 04-08-2013 05:55 PM
Revised Macro to backuo the normal.dotm New template/New normal.dotm kenglade Word 3 12-19-2011 04:00 PM
Revised Macro to backuo the normal.dotm How to get to normal.dotm Aiken_Bob Word 4 05-02-2011 02:41 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:20 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft