![]() |
#1
|
|||
|
|||
![]()
I need a macro for a word document (or template) that, upon Saving the document will append the filename with the current date (in yyy-mm-dd format). Subsequent saves of the new document (with the appended filename) will retain that filename.
Here's what I've tried so far. I still need to tie it into the Ctrl-S button, and make RetainFileName() work. Code:
Option Explicit ' Filename is Journal.docm whose fileNameLength=12 Public Sub Macro1() Dim fileNameLength As Integer fileNameLength = Len(ActiveDocument.Name) If fileNameLength > 12 Then RetainFileName Else NewFileName End If End Sub Private Sub RetainFileName() ActiveDocument.Save End Sub Private Sub NewFileName() Dim dt As Date Dim dd As Integer Dim mm As Integer Dim yyyy As Integer Dim strDt As String dt = Now dd = Day(dt) mm = Month(dt) yyyy = Year(dt) strDt = Str(yyyy) + "-" + Trim(Str(mm)) + "-" + Trim(Str(dd)) ActiveDocument.SaveAs2 FileName:="Journal " + strDt + ".docm", _ FileFormat:= _ wdFormatDocumentDefault, LockComments:=False, Password:="", _ AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _ EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _ :=False, SaveAsAOCELetter:=False, CompatibilityMode:=14 End Sub Last edited by macropod; 05-12-2012 at 10:21 PM. Reason: Added code tags & formatting |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Pmacdaddy | Project | 4 | 01-04-2022 09:53 AM |
![]() |
ketanco | Project | 1 | 02-08-2012 02:20 PM |
![]() |
czomberzdaniela | Word | 1 | 12-27-2011 07:18 PM |
![]() |
KIM SOLIS | Excel | 2 | 11-04-2011 06:09 PM |
![]() |
Styler001 | Word | 4 | 01-25-2010 06:40 PM |