General discussion

Locked

In VBA imbed system date in a file name

By watch4 ·
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".

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

In VBA imbed system date in a file name

by DKlippert In reply to In VBA imbed system date ...

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

Collapse -

In VBA imbed system date in a file name

by watch4 In reply to In VBA imbed system date ...

The question was auto-closed by TechRepublic

Collapse -

In VBA imbed system date in a file name

No points requested for this.
If you change that format string to "YYYYMMDD" you'll be able to sort your files by date.

Collapse -

In VBA imbed system date in a file name

by watch4 In reply to In VBA imbed system date ...

The question was auto-closed by TechRepublic

Collapse -

In VBA imbed system date in a file name

by watch4 In reply to In VBA imbed system date ...

This question was auto closed due to inactivity

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Forums