If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Add date to file name

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-18-06, 16:08
estefex estefex is offline
Registered User
 
Join Date: Jan 2004
Posts: 159
Add date to file name

Is there a way that i can add the date to a file name when i am saving it?
Reply With Quote
  #2 (permalink)  
Old 09-18-06, 20:00
shades shades is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 09-19-06, 10:38
estefex estefex is offline
Registered User
 
Join Date: Jan 2004
Posts: 159
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.
Reply With Quote
  #4 (permalink)  
Old 09-28-06, 13:51
Amazing_Spiderman Amazing_Spiderman is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On