![]() |
|
|
|
#1
|
|||
|
|||
|
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
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. |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
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 |
Appending the filename with the current date
|
sheeand | Word VBA | 2 | 05-14-2012 05:18 AM |
How to insert current date into default filename ?
|
czomberzdaniela | Word | 1 | 12-27-2011 07:18 PM |
Save Filename using Document Text
|
Knawl | Word | 11 | 10-10-2011 03:00 AM |