PC Review


Reply
Thread Tools Rate Thread

BeforeSave code that appends date - THANK YOU!!!!

 
 
=?Utf-8?B?YXdyZXg=?=
Guest
Posts: n/a
 
      31st May 2007
For those that have helped me out on a number of questions I have a nice
working bit of code. Nothing fancy but something that I feel I will use again
and again in the future.

It will append a datestamp to the filename and rename a worksheet tab with
date - edit as needed.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

On Error GoTo ErrorHandler
Application.EnableEvents = False
Application.DisplayAlerts = False 'Turns off pop if file is already in
the directory
Cancel = True

MsgBox "Saved as <YOUR FILENAME>" & Format(Now(), "yyyymmdd") & vbCr &
vbCr & _
ActiveWorkbook.Path, vbOK ' MSG with filename and filepath

Sheet1.Name = "As of " & Format(Now(), "MM-DD-YYYY") 'Renames worksheet
with appended date


ActiveWorkbook.SaveAs _
ActiveWorkbook.Path & Application.PathSeparator & _
"<YOUR FILENAME>" & Format(Now(), "yyyymmdd") 'Saves file to
path that file was opened in.
ErrorHandler:
Application.EnableEvents = True
Application.DisplayAlerts = True

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
beforesave code working sometimes...... =?Utf-8?B?YXdyZXg=?= Microsoft Excel Programming 3 29th May 2007 10:20 PM
Event (BeforeSave) - How to test VBA code? Dave P. can you hear me now? EagleOne Microsoft Excel Misc 3 14th Sep 2006 07:46 PM
Re: CREATING E-MAIL ATTACHMENT WITH 'BeforeSave Events' IN CODE Ron de Bruin Microsoft Excel Programming 4 8th Sep 2005 06:02 PM
Creating TWO-WAY E-Mail Attachments with 'BeforeSave Events' in Code for 2nd E-Mail Chuckles123 Microsoft Excel Programming 0 8th Sep 2005 05:56 PM
Code Problem in BeforeSave Event =?Utf-8?B?S2lyayBQLg==?= Microsoft Excel Programming 3 23rd Feb 2005 10:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:02 AM.