Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    164

    Unanswered: Add date to file name

    Is there a way that i can add the date to a file name when i am saving it?

  2. #2
    Join Date
    Oct 2003
    Posts
    1,091
    As in VBA code? Or just manually doing so when you save. If the later, then include something like 2006_09_18 at the end.
    old, slow, and confused
    but at least I'm inconsistent!

    Rich
    (retired Excel 2003 user, 3/28/2008)

    How to ask a question on forums

  3. #3
    Join Date
    Jan 2004
    Posts
    164
    Quote Originally Posted by shades
    As in VBA code? Or just manually doing so when you save. If the later, then include something like 2006_09_18 at the end.
    well, I was wondering if there was some type of tag i would be able to put at the end of the file so that it could place the date at the end of whatever i name the file.

    for example I want to save a workbook with the name of "numbers"+"date".xls

    I was wondering if i would be able to do something like numbers${date}.xls where ${date} is pulling in the date.

    I hope this helps a bit.

  4. #4
    Join Date
    Aug 2006
    Posts
    21
    Well Estefex,

    Add the code below somewhere in your VBA Module or Create a Macro with a Shortcut and insert the following below
    ---------------------------------------------------
    Dim sAppPath As String, sFileName As String, sDate As String

    sAppPath = "c:\"
    sDate = Replace(FormatDateTime(Now(), vbShortDate), "/", ".")
    sFileName = sAppPath & "Numbers - " & sDate & ".xls"

    ActiveWorkbook.SaveAs Filename:= _
    sFileName, FileFormat:= _
    xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
    , CreateBackup:=False
    ---------------------------------------------------
    Will Generate: Numbers - 9.28.2006

    In addition you can make this more robust by adding an if FileExist statement to change the filename accordingly if you need to save more numbers in one day but there are other ways just my modifying the code above in the sDate section. Check for differences below.

    ---------------------------------------------------
    Dim sAppPath As String, sFileName As String, sDate As String

    sAppPath = "c:\"
    sDate = Replace(Replace(FormatDateTime(Now(), vbGeneralDate), "/", "."), ":", ".")
    sFileName = sAppPath & "Numbers - " & sDate & ".xls"

    ActiveWorkbook.SaveAs Filename:= _
    sFileName, FileFormat:= _
    xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
    , CreateBackup:=False
    ---------------------------------------------------
    Will Generate: Numbers - 9.28.2006 1.48.56 PM.xls

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •