Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding date to file name

Status
Not open for further replies.

mts176

MIS
Apr 17, 2001
109
0
0
US
When creating a delimited file how do I put the date in the file name?
Also if the file is created at 12:01 on Jan 21 how do I make the date say Jan 20?
 
Try this:
Set a reference to the scripting runtime

Option Explicit
Dim fs As Scripting.FileSystemObject
Dim ts As Scripting.TextStream
Dim strFile As String


Set fs = New Scripting.FileSystemObject
strFile = "c:\MyFilename " & Format(Now, "mm-dd-yyyy") & ".txt"
Set ts = fs.CreateTextFile(strFile, True)
'Do whatever
ts.Close

Since the codeuses the NOW function the date should be correct at 12:01.

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top