Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-13-2017, 11:19 AM
Charles Kenyon Charles Kenyon is offline Save document multiple times with date as filename Windows 10 Save document multiple times with date as filename Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,582
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Save document multiple times with date as filename How can I save a Word Document as a PDF file with a merged field filename? kp2009 Word VBA 5 08-27-2015 11:45 PM
Using DocProperty Field Codes multiple times in the same document trueimage Word 2 09-18-2013 04:44 PM
Save document multiple times with date as filename Appending the filename with the current date sheeand Word VBA 2 05-14-2012 05:18 AM
Save document multiple times with date as filename How to insert current date into default filename ? czomberzdaniela Word 1 12-27-2011 07:18 PM
Save document multiple times with date as filename Save Filename using Document Text Knawl Word 11 10-10-2011 03:00 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:36 AM.


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