#1
|
|||
|
|||
Save document multiple times with date as filename
Hi All,
I have a document that I use for work which is filled in every day with details of the shift to pass on to the shift coming on. These files are saved 01 01 2017 day 01 01 2017 Night 02 01 2017 day 02 01 2017 Night and so on, and filed for future reference so they are always saved with the date as the filename. I also have two date fields in the file itself that I want to change with the filename. So what I am asking is! Is there a way to save the file multiple times with the dates changing in the text fields and the file name, is this possible. |
#2
|
||||
|
||||
This is easily achieved with a macro, but how and when do you intend to save the documents. e.g. Today do you want to save the two documents with tomorrow's date or the two documents with today's date orthe two documents with a raft of dates - in which case which?
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Quote:
I want to save the same document for every day of each month, all in one day. Its basically a diary of the days work so I would want one for every day of the year that I will organise into separate folders one for each month. So if its the 4th July they can goto the document dated 04 07 2017 and make the entry for the day. The problem is people keep opening the previous days document make the entry for the day and they don't change the filename date and save over a previous document so I want to create a years worth of documents so staff can just open the one that is dated for that day and they don't have to think about saving the file with the correct date. Sorry I hope I am making sense. If possible I would also like the macro to change the date inside the document itself. |
#4
|
||||
|
||||
Quote:
See: https://support.office.com/en-us/art...2-1191BCE57DEB https://support.office.com/en-us/art...2-57A2168C1E89
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
When you create your template, you can put in CREATEDATE fields for both date and time if you want. Using Date Fields in Microsoft Word
Unlike the DATE field, these will remain fixed. I agree, strongly, with Paul that you want to be using a template. You can use a macro in the template to attach the date and time to the filename. |
#6
|
|||
|
|||
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. |
#7
|
|||
|
|||
That macro was designed to be called from another macro that would supply a name. You could simplify the process:
Code:
Public Sub FileSave() ' Run as substitute for FileSave to add date to default document names ' Put in a document or global template as public macro ' Base name comes from the Title Property in the template 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 ' 'get name from title property strName = ActiveDocument.BuiltInDocumentProperties("Title").Value ' 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 |
|
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 |