Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default auto save on exit while at the same time rename workbook...

Hi,
Is it possible to auto save on exit of workbook, while at the same time
rename the workbook to reflect the contents of cell A1 of sheet1. I want to
auto save a workbook on exit and rename the workbook to the date that appears
in cell A1 of sheet1.

Thank You
Brian
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default auto save on exit while at the same time rename workbook...

Hi Brian,

When the workbook is closed, the following event code will save the workbook
as the date contained in A1 on the first worksheet. As written, the file
will be saved with a name in the format yyyy-mm-dd. this format has the
advantage of allowing the various versions to be sorted chronologically.

Again as written, if A1 is blank, or A1 cannot be intepreted as a valid
date, then the file will *not* be saved and the normal pre-close alert will
be shown asking the user whether changes should be saved (to the existing
file).

You may wish to consider an alternative, default treatment for an empty or
non-date entry in A1.

Note that I have assumed that when the file is saved to the A1 date, the
original file is not updated. If that does not correspond to your intent,
please post back for a suitable variant.

This code should be pasted in the workbook's ThisWorkbook module
(right-click the Excel icon at the extreme left of the menu bar | View
Code):

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim rng As Range
Set rng = Me.Sheets("Sheet1").Range("A1")
If IsDate(rng) Then
Me.SaveAs Format(rng.Value, "yyyy-mm-dd")
ThisWorkbook.Saved = True
End If

End Sub

---
Regards,
Norman



"Brian" wrote in message
...
Hi,
Is it possible to auto save on exit of workbook, while at the same time
rename the workbook to reflect the contents of cell A1 of sheet1. I want
to
auto save a workbook on exit and rename the workbook to the date that
appears
in cell A1 of sheet1.

Thank You
Brian



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default auto save on exit while at the same time rename workbook...

Press Alt+F11 and put this the module "ThisWorkbook":

Sub Workbook_BeforeClose(Cancel As Boolean)
Dim wb As Workbook
Dim wbname As String
Set wb = ActiveWorkbook
wbname = Sheets("Sheet1").Range("A1").Value
wb.SaveAs "C:\My Documents\" _
& Format(wbname, "mm-dd-yy") & ".xls"
End Sub
---

HTH
Jason
Atlanta, GA

-----Original Message-----
Hi,
Is it possible to auto save on exit of workbook, while

at the same time
rename the workbook to reflect the contents of cell A1 of

sheet1. I want to
auto save a workbook on exit and rename the workbook to

the date that appears
in cell A1 of sheet1.

Thank You
Brian
.

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
Auto Rename Excel Sheets in Workbook Kulin Shah Excel Worksheet Functions 12 December 25th 06 03:27 PM
how to set auto protect workbook on exit? West Excel Worksheet Functions 4 October 2nd 06 03:19 AM
Auto rename and save prompt needed. Gizmo63 Excel Worksheet Functions 0 February 7th 06 02:00 PM
Macro: Exit active workbook without save? Don Excel Worksheet Functions 0 May 20th 05 06:47 AM
How do i auto rename a worksheet to be the same filename as save f Catherine Excel Worksheet Functions 1 December 1st 04 10:17 AM


All times are GMT +1. The time now is 11:37 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"