PC Review


Reply
Thread Tools Rate Thread

How to add Date Stamp to SaveAs "file name" within VBA for Excel?

 
 
fisch4bill
Guest
Posts: n/a
 
      12th Aug 2009
I have written some VBA code to pull several columns from an Excel
spreadsheet and save these in their own file of *.csv format. However, the
end users would greatly benefit from having the saved date as part of the
filename. I've tried several different methods in my code, but, none are
working. The rest of the code works as intended (I get the new file created
and saved with the new filename).

The relevant code is as follows:

Workbooks.Add
Windows(Sheet_Name).Activate
Cells.Select
Selection.Copy
Workbooks("Book1").Worksheets("Sheet1").Activate
Cells.Select
ActiveSheet.Paste
Sheets(Sheets.Count).Name = "Crimson_Info"
ActiveWorkbook.SaveAs
Filename:="\\Cmc-thor\Infosystems\Projects\Crimson\Crimson_Info.csv",
FileFormat:=xlCSV


 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      12th Aug 2009
ActiveWorkbook.SaveAs _
Filename:="\\Cmc-thor\Infosystems\Projects\Crimson\Crimson_Info" _
& format(date,"yyyy-mm-dd") & ".csv", _
FileFormat:=xlCSV

Or include the date and time????

ActiveWorkbook.SaveAs _
Filename:="\\Cmc-thor\Infosystems\Projects\Crimson\Crimson_Info" _
& format(now,"yyyymmdd--hhmmss") & ".csv", _
FileFormat:=xlCSV

Remember that filenames can't use colons or slashes in their names--that's why
the Format() stuff didn't include them.

fisch4bill wrote:
>
> I have written some VBA code to pull several columns from an Excel
> spreadsheet and save these in their own file of *.csv format. However, the
> end users would greatly benefit from having the saved date as part of the
> filename. I've tried several different methods in my code, but, none are
> working. The rest of the code works as intended (I get the new file created
> and saved with the new filename).
>
> The relevant code is as follows:
>
> Workbooks.Add
> Windows(Sheet_Name).Activate
> Cells.Select
> Selection.Copy
> Workbooks("Book1").Worksheets("Sheet1").Activate
> Cells.Select
> ActiveSheet.Paste
> Sheets(Sheets.Count).Name = "Crimson_Info"
> ActiveWorkbook.SaveAs
> Filename:="\\Cmc-thor\Infosystems\Projects\Crimson\Crimson_Info.csv",
> FileFormat:=xlCSV


--

Dave Peterson
 
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
"Date Created" section to date stamp when appointments were made =?Utf-8?B?dGhlbWRyYWdvbnM=?= Microsoft Outlook Calendar 1 1st Aug 2006 02:51 PM
"update date and time stamp" with date smart tag =?Utf-8?B?TG9uZ2hvcm4gaW4gTkM=?= Microsoft Word Document Management 1 14th Mar 2006 08:37 PM
How do I put a "date & time saved" stamp inside an Excel Wksht? =?Utf-8?B?QmlsbA==?= Microsoft Excel Programming 1 12th May 2005 05:03 PM
Re: How do I put a "date & time saved" stamp inside an Excel Wksht? Mangesh Yadav Microsoft Excel Programming 0 10th May 2005 12:20 PM
File "Last Accessed" Date and Time Stamp Bob Microsoft Windows 2000 File System 0 12th Nov 2003 06:49 PM


Features
 

Advertising
 

Newsgroups
 


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