Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default date in filename

I would like to write a macro that will save a file with the date in the file
name before it prints, print the sheet, clear the data, then save as a
different file. Here's what I have:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
ActiveWorkbook.SaveAs Filename:="J:\My Documents\APS Bodies &
Options\Pacific-APS Order List " & Left(Now(), 8) & ".xls"
Application.EnableEvents = False
Cancel = True
ActiveSheet.PrintOut
Application.EnableEvents = True
Range("A16:J41").ClearContents
ActiveWorkbook.SaveAs Filename:="J:\My Documents\APS Bodies &
Options\Pacific-APS Order List.xls"
End Sub

I would like the file that is saved to have this file name: Pacific-APS
Order List 040405.xls. I can't figure out how to get the now() function to do
this. Any suggestions? I need to be able to do this any month or any day of
the year.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default date in filename

Suggest you use 20050404 for the date yyyymmdd so you can
look at the directory in alphabetical order.

http://www.mvps.org/dmcritchie/excel/backup.htm
--
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"JCanyoneer" wrote in message ...
I would like to write a macro that will save a file with the date in the file
name before it prints, print the sheet, clear the data, then save as a
different file. Here's what I have:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
ActiveWorkbook.SaveAs Filename:="J:\My Documents\APS Bodies &
Options\Pacific-APS Order List " & Left(Now(), 8) & ".xls"
Application.EnableEvents = False
Cancel = True
ActiveSheet.PrintOut
Application.EnableEvents = True
Range("A16:J41").ClearContents
ActiveWorkbook.SaveAs Filename:="J:\My Documents\APS Bodies &
Options\Pacific-APS Order List.xls"
End Sub

I would like the file that is saved to have this file name: Pacific-APS
Order List 040405.xls. I can't figure out how to get the now() function to do
this. Any suggestions? I need to be able to do this any month or any day of
the year.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding date to filename? teepee[_3_] Excel Discussion (Misc queries) 5 April 15th 08 10:05 PM
set filename to <filename-date on open bob engler Excel Worksheet Functions 2 July 13th 06 05:11 AM
Save date in filename Mike Excel Programming 6 February 24th 04 02:12 PM
Filename with current Date() Chip Pearson Excel Programming 1 January 8th 04 07:18 AM
Filename with current Date() Graham[_5_] Excel Programming 1 January 8th 04 07:15 AM


All times are GMT +1. The time now is 01:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"