Automatic Date and time in word document title

  • Thread starter Thread starter dakke
  • Start date Start date
D

dakke

Is there a way to include the date and time in the title of the document in
that way that each time you save the document the data and time are updated
and as such stored as a brandnew file?

eg:
Document title: Test 11-1-2008 11:12 pm.doc
Modify and work on another day making it:
Test 13-1-2008 08:32 pm.doc

All without manually updating the file name?
 
Create a macro called FileSave()

Dim fname as String
fname = InputBox("Enter the filename", "File Save As")
With ActiveDocument
.Variables("varfname").Value = fname
.SaveAs fname & Format(Now(), "dd-M-yyyy hh:mm AMPM")
End With

and for the subsequent saves a macro called FileSaveAs()

With ActiveDocument
.SaveAs .Variables("varfname").Value & Format(Now(), "dd-M-yyyy hh:mm
AMPM")
End With

If you put these macros in a Global template, they corresponding one will
run whenever you use the File>SaveAs or File>Save command.



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
Thanks for the reply.

I'm not familar with macro's, but this is the error I got:
Run-time error '5152';
This is not a valied file name.
Try on of the following:
* Check the path to make sure it was typed correctly.
* Select a file from the list of files and folders.
(test16-1-2008 02:47 PM)


Here's the macro I created based on your advice:

Sub Filesave()
Dim fname As String
fname = InputBox("Enter the filename", "File Save As")
With ActiveDocument
..Variables("varfname").Value = fname
..SaveAs fname & Format(Now(), "dd-M-yyyy hh:mm AMPM")
End With
End Sub

Sub FilesaveAs()
End Sub
With ActiveDocument
.SaveAs .Variables("varfname").Value & Format(Now(), "dd-M-yyyy hh:mm AMPM ")
End With
End Sub

So I think it kinda does a thing that comes close, but...
It also pops up a window asking to 'Enter the filename', which it shouldnt
do ideally since it should take the 'actual' filename and simply update the
date and time. Should have been more clear on this. However, entering the
filename does not work: 'test', 'test.doc' doesn't do a thing.
Is there a way to do this (might be useful to create a field with the title
like 'test' and that the macro grabs the field and adds the data and time)

Your help is much appreciated, but also points out that I really need to
learn more about the macro's.
 
Oops, the colon is causing the problem. Replace it in the Format() function
with something else that suits your fancy.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top