LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Code issue - before_save() - Filename with date stamp - worksheet

I missed the format problem that Rick caught.

I'd use this code instead:

Option Explicit
Sub SaveMeNow()

With ActiveSheet
.Name = "As of " & Format(Now, "MM-DD-YYYY")
End With

ActiveWorkbook.saveas filename:="{FILENAME}" _
& Format(Now, "yyyymmdd") & ".xls", fileformat:=xlworkbooknormal

End Sub

Dave Peterson wrote:

You can only change the workbook's name by saving it as that name.

Instead of using workbook_beforesave, have you thought about using a dedicated
macro that does the rename and save:

Option Explicit
Sub SaveMeNow()

With ActiveSheet
.Name = "As of " & Format(Now, "MM-DD-YYYY")
End With

ActiveWorkbook.saveas filename:="{FILENAME}" _
& Format(Now(), "yyyymmdd" & ".xls"), fileformat:=xlworkbooknormal

End Sub

It would scare me using the activesheet and the date. I may be saving the wrong
sheet and I may get an error if that name already exists.

You could use the codename instead and maybe add the time???

Option Explicit
Sub SaveMeNow()

With Sheet1
.Name = "As of " & Format(Now, "MM-DD-YYYY__hhmmss")
End With

ActiveWorkbook.saveas filename:="{FILENAME}" _
& Format(Now(), "yyyymmdd" & ".xls"), fileformat:=xlworkbooknormal

End Sub

Use this to get the codename of the activesheet.

msgbox activesheet.codename

awrex wrote:

Could someone tell this tourist why this is not working please??

Private Sub Workbook_BeforeSave()

With ActiveSheet
.Name = "As of " & Format(Now(), "MM-DD-YYYY")
End With

With ActiveWorkbook
.Name = "{FILENAME}" & Format(Now(), "yyyymmdd" & ".xls")
End With

End Sub


--

Dave Peterson


--

Dave Peterson
 
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
Date stamp when a value is entered in a cell on another worksheet bbrant2 Excel Worksheet Functions 1 January 21st 08 05:27 PM
How date stamp & save filename? jkt Excel Programming 2 May 8th 07 02:30 AM
Multiple Date Stamp & Worksheet Change macros alex3867[_5_] Excel Programming 1 August 11th 06 06:04 AM
Filename Issue Zeroman Excel Programming 3 November 18th 04 05:00 PM
Need Before_Save code Phil Hageman Excel Programming 13 July 10th 03 11:55 AM


All times are GMT +1. The time now is 05:22 PM.

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

About Us

"It's about Microsoft Excel"