Discussion Locked

In VBA imbed system date in a file name

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I am writing a very simple copy routine that is to capture a report for each day. I need to rename the file each time I copy it to a historic directory, so that the file name will include the File Name and the current system date. I have tried a number of things and although I can always get a file name + system date in a msgbox - I haven't found the right syntax to actually name the file with that combination "Population Report 11/02/02".

5 replies

by dklippert

In the folllowing code, the "Historic Directory" must exist (or change the name to what ever you want, The date can not use "/", so I used "-"
There is an empty line between each line of code to compensate for text wrap.

Sub SaveFilenameAndDate()

Dim PathAndFileName As String

PathAndFileName = "C:\Historic Directory\Population Report "

PathAndFileName = PathAndFileName & Format(Date, "mm-dd-yy")

PathAndFileName = PathAndFileName & ".doc"

ActiveDocument.SaveAs PathAndFileName

End Sub

This discussion is closed to new replies.