View Single Post
 
Old 03-13-2017, 11:19 AM
Charles Kenyon Charles Kenyon is offline Windows 10 Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,530
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

The following pair of macros work to append a date to whatever is in the Title document property in the template for a new document.

Code:
Public Sub SaveWithDate(Optional strName As String)
    ' Run as substitute for FileSave to add date to default document names
    ' Put in a document or global template as public macro
    ' This is called from other macros which may supply a name strName
    ' If strName is supplied, it is used as the base name, otherwise the base comes from the Title Property
     '
    Dim dlgSave As Dialog
    On Error Resume Next
    '   
    If Len(ActiveDocument.Path) > 0 Then
      ' The document has already been saved at least once.
      ' Just save and exit the macro.
      ActiveDocument.Save
      Exit Sub
    End If
    '
    If strName = "" Then strName = strName & ActiveDocument.BuiltInDocumentProperties("Title").Value        'get name in title
    ActiveDocument.BuiltInDocumentProperties("Title").Value = strName
    '    
    strName = strName & " " & Format((Year(Now() + 1) Mod 100), "20##") & "-" & _
        Format((Month(Now() + 1) Mod 100), "0#") & "-" & _
        Format((Day(Now()) Mod 100), "0#")
    '
    Set dlgSave = Dialogs(wdDialogFileSaveAs)
    With dlgSave
        .Name = strName
        .Show
        
    End With
End Sub

Sub FileSave()
    Application.Run "SaveWithDate"
End Sub
That code should be in your template. It intercepts the FileSave command and proposes a name. If the file already has a name, it simply saves.

Your users, I would hope, could add the DAY or NIGHT to the name.

Note, this does not intercept the SaveAs command. It will activate is someone tries to close a new document without saving and then responds to the query that they do want to save it.

I wrote this with substantial help from others on one of these forums. The date will be in the format YYYY-MM-DD. When appended to a standard name, the files sort nicely in alphabetical order. You could change the order to what you are using now, I suppose.

See Installing Macros for information about how to use this code if you don't know.
Reply With Quote