Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default BeforeSave code that appends date - THANK YOU!!!!

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
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
beforesave code working sometimes...... awrex Excel Programming 3 May 29th 07 10:20 PM
Event (BeforeSave) - How to test VBA code? Dave P. can you hear me now? EagleOne Excel Discussion (Misc queries) 3 September 14th 06 07:46 PM
CREATING E-MAIL ATTACHMENT WITH 'BeforeSave Events' IN CODE Chuckles123[_102_] Excel Programming 16 September 8th 05 06:02 PM
Creating TWO-WAY E-Mail Attachments with 'BeforeSave Events' in Code for 2nd E-Mail Chuckles123[_112_] Excel Programming 0 September 8th 05 05:56 PM
Code Problem in BeforeSave Event Kirk P. Excel Programming 3 February 23rd 05 10:08 PM


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

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"