Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
beforesave code working sometimes...... | Excel Programming | |||
Event (BeforeSave) - How to test VBA code? Dave P. can you hear me now? | Excel Discussion (Misc queries) | |||
CREATING E-MAIL ATTACHMENT WITH 'BeforeSave Events' IN CODE | Excel Programming | |||
Creating TWO-WAY E-Mail Attachments with 'BeforeSave Events' in Code for 2nd E-Mail | Excel Programming | |||
Code Problem in BeforeSave Event | Excel Programming |