PC Review


Reply
Thread Tools Rate Thread

Add Date to File Name

 
 
Jenny B.
Guest
Posts: n/a
 
      22nd Jun 2008
Hi All,
I use the below to save a copy of my worksheet to my desktop before its
contents are cleared. I would like to add a now() or today() date stamp to
the fName. Any ideas how to do that?

I’ve combined the ranges on my excel spreadsheet cell H5 with a text date
style =H5& " "&TEXT(TODAY(),"mm/dd/yy"). When I try to add this to the
macro below, I get this error –
Run-Time error 1004.

Any thoughts on how I can have the output file contain my H5 value which is
text and today’s date?

Thank you – Jenny B.


Sub Save()

Dim myPath As String
Dim nRng As Range
Dim fName As String
Set nRng = Range("H5")

ActiveSheet.Copy

Call DeleteAllCode
ActiveSheet.Shapes("Send").Visible = False
myPath = "C:\Documents and Settings\Name Here\Desktop\"
fName = nRng.Value & ".xls"

ActiveWorkbook.SaveAs filename:= _
myPath & fName, FileFormat:= _
xlNormal, Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=False, _
CreateBackup:=False
ActiveWorkbook.Close
Call TransfertoLog
Call CLEAR
ActiveSheet.Visible = False

End Sub

 
Reply With Quote
 
 
 
 
FSt1
Guest
Posts: n/a
 
      22nd Jun 2008
hi
wild guessing here.
slashes are forbidden as a file naming conviction. no slashes in a file name.
try this....
style =H5& " "&TEXT(TODAY(),"mmddyy")
your date will end up looking like this......062108.
i use this style when i'm adding a date to a file name. mainly because
slashes are forbidden.

regards
FSt1

"Jenny B." wrote:

> Hi All,
> I use the below to save a copy of my worksheet to my desktop before its
> contents are cleared. I would like to add a now() or today() date stamp to
> the fName. Any ideas how to do that?
>
> I’ve combined the ranges on my excel spreadsheet cell H5 with a text date
> style =H5& " "&TEXT(TODAY(),"mm/dd/yy"). When I try to add this to the
> macro below, I get this error –
> Run-Time error 1004.
>
> Any thoughts on how I can have the output file contain my H5 value which is
> text and today’s date?
>
> Thank you – Jenny B.
>
>
> Sub Save()
>
> Dim myPath As String
> Dim nRng As Range
> Dim fName As String
> Set nRng = Range("H5")
>
> ActiveSheet.Copy
>
> Call DeleteAllCode
> ActiveSheet.Shapes("Send").Visible = False
> myPath = "C:\Documents and Settings\Name Here\Desktop\"
> fName = nRng.Value & ".xls"
>
> ActiveWorkbook.SaveAs filename:= _
> myPath & fName, FileFormat:= _
> xlNormal, Password:="", _
> WriteResPassword:="", _
> ReadOnlyRecommended:=False, _
> CreateBackup:=False
> ActiveWorkbook.Close
> Call TransfertoLog
> Call CLEAR
> ActiveSheet.Visible = False
>
> End Sub
>

 
Reply With Quote
 
Jenny B.
Guest
Posts: n/a
 
      22nd Jun 2008
Thank your for you help. You were right on the money and it now works great.
I should have known better and remembered that the slashes represent a path
and that’s why I was getting that annoying error.

Thanks again – Jenny B.


"FSt1" wrote:

> hi
> wild guessing here.
> slashes are forbidden as a file naming conviction. no slashes in a file name.
> try this....
> style =H5& " "&TEXT(TODAY(),"mmddyy")
> your date will end up looking like this......062108.
> i use this style when i'm adding a date to a file name. mainly because
> slashes are forbidden.
>
> regards
> FSt1
>
> "Jenny B." wrote:
>
> > Hi All,
> > I use the below to save a copy of my worksheet to my desktop before its
> > contents are cleared. I would like to add a now() or today() date stamp to
> > the fName. Any ideas how to do that?
> >
> > I’ve combined the ranges on my excel spreadsheet cell H5 with a text date
> > style =H5& " "&TEXT(TODAY(),"mm/dd/yy"). When I try to add this to the
> > macro below, I get this error –
> > Run-Time error 1004.
> >
> > Any thoughts on how I can have the output file contain my H5 value which is
> > text and today’s date?
> >
> > Thank you – Jenny B.
> >
> >
> > Sub Save()
> >
> > Dim myPath As String
> > Dim nRng As Range
> > Dim fName As String
> > Set nRng = Range("H5")
> >
> > ActiveSheet.Copy
> >
> > Call DeleteAllCode
> > ActiveSheet.Shapes("Send").Visible = False
> > myPath = "C:\Documents and Settings\Name Here\Desktop\"
> > fName = nRng.Value & ".xls"
> >
> > ActiveWorkbook.SaveAs filename:= _
> > myPath & fName, FileFormat:= _
> > xlNormal, Password:="", _
> > WriteResPassword:="", _
> > ReadOnlyRecommended:=False, _
> > CreateBackup:=False
> > ActiveWorkbook.Close
> > Call TransfertoLog
> > Call CLEAR
> > ActiveSheet.Visible = False
> >
> > End Sub
> >

 
Reply With Quote
 
Rob L
Guest
Posts: n/a
 
      24th Jun 2008
As well, if you format your date as yymmdd, (or yyyy mm dd as I do) then the
files will sort in the right time order....

OM

"Jenny B." <(E-Mail Removed)> wrote in message
news:57F0D66C-570E-4C83-AC7E-(E-Mail Removed)...
> Thank your for you help. You were right on the money and it now works
> great.
> I should have known better and remembered that the slashes represent a
> path
> and that's why I was getting that annoying error.
>
> Thanks again - Jenny B.
>
>
> "FSt1" wrote:
>
>> hi
>> wild guessing here.
>> slashes are forbidden as a file naming conviction. no slashes in a file
>> name.
>> try this....
>> style =H5& " "&TEXT(TODAY(),"mmddyy")
>> your date will end up looking like this......062108.
>> i use this style when i'm adding a date to a file name. mainly because
>> slashes are forbidden.
>>
>> regards
>> FSt1
>>
>> "Jenny B." wrote:
>>
>> > Hi All,
>> > I use the below to save a copy of my worksheet to my desktop before its
>> > contents are cleared. I would like to add a now() or today() date
>> > stamp to
>> > the fName. Any ideas how to do that?
>> >
>> > I've combined the ranges on my excel spreadsheet cell H5 with a text
>> > date
>> > style =H5& " "&TEXT(TODAY(),"mm/dd/yy"). When I try to add this to
>> > the
>> > macro below, I get this error -
>> > Run-Time error 1004.
>> >
>> > Any thoughts on how I can have the output file contain my H5 value
>> > which is
>> > text and today's date?
>> >
>> > Thank you - Jenny B.
>> >
>> >
>> > Sub Save()
>> >
>> > Dim myPath As String
>> > Dim nRng As Range
>> > Dim fName As String
>> > Set nRng = Range("H5")
>> >
>> > ActiveSheet.Copy
>> >
>> > Call DeleteAllCode
>> > ActiveSheet.Shapes("Send").Visible = False
>> > myPath = "C:\Documents and Settings\Name Here\Desktop\"
>> > fName = nRng.Value & ".xls"
>> >
>> > ActiveWorkbook.SaveAs filename:= _
>> > myPath & fName, FileFormat:= _
>> > xlNormal, Password:="", _
>> > WriteResPassword:="", _
>> > ReadOnlyRecommended:=False, _
>> > CreateBackup:=False
>> > ActiveWorkbook.Close
>> > Call TransfertoLog
>> > Call CLEAR
>> > ActiveSheet.Visible = False
>> >
>> > End Sub
>> >



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Output Date Created and Date Modified to a txt file using a batch file mhel_0414 Windows XP 0 12th Sep 2009 07:00 AM
Recovering File Info Specifically Save Date or Print Date Gadgetgw Microsoft Excel Misc 4 6th Oct 2008 08:43 PM
Copying file; original date not retained; changed to date of copy =?Utf-8?B?aWNlYnV0Y2htYW4zOTQ0?= Microsoft Outlook Discussion 1 8th Mar 2006 10:01 PM
File folder creation date is replaced with the date copied. =?Utf-8?B?enp6?= Windows XP General 2 9th Feb 2005 02:02 PM
Excel Date - Auto enter file creation date (free chocolate for help) arielax Microsoft Excel Misc 6 29th Apr 2004 02:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:33 PM.