ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Current Date & Save on close (https://www.excelbanter.com/excel-programming/373408-current-date-save-close.html)

jk

Current Date & Save on close
 
I need to have some code so when the users open the workbook, the current
date would be inserted into cell A1. Then, after the workbook has been used,
an auto save on close in case they forget to use the save menu option. Can
these two things be done?

Bob Phillips

Current Date & Save on close
 
Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
End Sub

Private Sub Workbook_Open()
Worksheets(1).Range("A1").Value = Date
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"jk" wrote in message
...
I need to have some code so when the users open the workbook, the current
date would be inserted into cell A1. Then, after the workbook has been

used,
an auto save on close in case they forget to use the save menu option. Can
these two things be done?




jk

Current Date & Save on close
 
Thanks Bob,

This works well. In the event a user wants to save the file as another name
to the desktop, can a "save as" prompt appear to save on close?

"Bob Phillips" wrote:

Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
End Sub

Private Sub Workbook_Open()
Worksheets(1).Range("A1").Value = Date
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"jk" wrote in message
...
I need to have some code so when the users open the workbook, the current
date would be inserted into cell A1. Then, after the workbook has been

used,
an auto save on close in case they forget to use the save menu option. Can
these two things be done?






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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com