Word

Save Document with Date on Close

Ease of Use

Intermediate

Version tested with

2000 

Submitted by:

Graham Skan

Description:

When you close a document with this macro in it, it saves the file with a specified name, followed by the date in whatever format you choose. 

Discussion:

Suppose you must fill out the same form every day; perhaps a daily log of what you worked on that day, or some other type of diary. You can put this macro in your document, and when you close the document, it'll automatically save it with a specified name, followed by a date format that you can specify. 

Code:

instructions for use

			

Private Sub Document_Close() Dim FileName As String 'Set MyFile = ActiveDocument.Name FileName = "LogID" & Format(Now, "mm-dd-yy") ActiveDocument.SaveAs FileName End Sub

How to use:

  1. Copy the code above.
  2. Open your document; preferably it's a template you're using.
  3. Hit Alt+F11 to open the Visual Basic Editor (VBE).
  4. At left, double-click on ThisDocument.
  5. Paste the code into the code window at right.
  6. Change "LogID" to whatever you desire.
  7. Change "mm-dd-yy" to "dd-mm-yyyy" or any other format you choose.
  8. Close the VBE, save the file (important!).
 

Test the code:

  1. Close the file without using the Save or Save as options.
 

Sample File:

No Attachment 

Approved by Anne Troy


This entry has been viewed 160 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express