Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a need to automatically save the current date to a cell in an excel spreadsheet every time the sheet is saved.
Today() always returns the current date, so once I open the sheet on a new day I can no longer see the date the information was last updated, i.e. saved. Any help would be appreciated. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
David,
Are you familiar with Visual Basic? If so, try this code in ThisWorkbook section. Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Sheets("Sheet1").Select Range("A1").Select ActiveCell.Value = Now End Sub Actually, this returns an entire Date/Time stamp. If you wanted just the date you could use DateSerial(Year(Now),Month(Now),Day(Now)) where "Now" is above. Dave "David" wrote: I have a need to automatically save the current date to a cell in an excel spreadsheet every time the sheet is saved. Today() always returns the current date, so once I open the sheet on a new day I can no longer see the date the information was last updated, i.e. saved. Any help would be appreciated |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi David,
in the ThisWorkbook module - Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _ Cancel As Boolean) 'if don't want date if no changes since last save If ThisWorkbook.Saved = True Then Exit Sub On Error Resume Next Application.EnableEvents = False Worksheets("Sheet1").Range("A1") = Now Worksheets("Sheet1").Range("A2") = Date Application.EnableEvents = True End Sub Handy keyboard short cuts Ctrl ; semicolon - date with shift or colon - time Regards, Peter T PS FYI, my newsreader removed an attachment from your post it decided was unsafe. "David" wrote in message ... I have a need to automatically save the current date to a cell in an excel spreadsheet every time the sheet is saved. Today() always returns the current date, so once I open the sheet on a new day I can no longer see the date the information was last updated, i.e. saved. Any help would be appreciated. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel A Boolean) ThisWorkbook.Sheets("Sheet1").Range("A1").Value = Now End Sub 1. Replace "Sheet1" with the name of the sheet where you want to inser the date. 2. Replace "A1" with the address of the cell where you want to ente the date. The Workbook_beforeSave event is an event of "Thisworkbook" object. Juan Carlo -- cscor ----------------------------------------------------------------------- cscorp's Profile: http://www.excelforum.com/member.php...fo&userid=2401 View this thread: http://www.excelforum.com/showthread.php?threadid=37655 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Peter, yours seems to have worked best of all the solutions I
received. The others may have worked just as well if I knew more about VB. Can I take care of formatting so it ends up as March 12, 2005 in your code vs. in the spreadsheet? Thanks again for your help. "Peter T" <peter_t@discussions wrote in message ... Hi David, in the ThisWorkbook module - Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _ Cancel As Boolean) 'if don't want date if no changes since last save If ThisWorkbook.Saved = True Then Exit Sub On Error Resume Next Application.EnableEvents = False Worksheets("Sheet1").Range("A1") = Now Worksheets("Sheet1").Range("A2") = Date Application.EnableEvents = True End Sub Handy keyboard short cuts Ctrl ; semicolon - date with shift or colon - time Regards, Peter T PS FYI, my newsreader removed an attachment from your post it decided was unsafe. "David" wrote in message ... I have a need to automatically save the current date to a cell in an excel spreadsheet every time the sheet is saved. Today() always returns the current date, so once I open the sheet on a new day I can no longer see the date the information was last updated, i.e. saved. Any help would be appreciated. |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Use this then
Worksheets("Sheet1").Range("A1").Value = Format(Date, "mmm dd yyyy") -- Regards Ron de Bruin http://www.rondebruin.nl "David" wrote in message ... Thanks Peter, yours seems to have worked best of all the solutions I received. The others may have worked just as well if I knew more about VB. Can I take care of formatting so it ends up as March 12, 2005 in your code vs. in the spreadsheet? Thanks again for your help. "Peter T" <peter_t@discussions wrote in message ... Hi David, in the ThisWorkbook module - Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _ Cancel As Boolean) 'if don't want date if no changes since last save If ThisWorkbook.Saved = True Then Exit Sub On Error Resume Next Application.EnableEvents = False Worksheets("Sheet1").Range("A1") = Now Worksheets("Sheet1").Range("A2") = Date Application.EnableEvents = True End Sub Handy keyboard short cuts Ctrl ; semicolon - date with shift or colon - time Regards, Peter T PS FYI, my newsreader removed an attachment from your post it decided was unsafe. "David" wrote in message ... I have a need to automatically save the current date to a cell in an excel spreadsheet every time the sheet is saved. Today() always returns the current date, so once I open the sheet on a new day I can no longer see the date the information was last updated, i.e. saved. Any help would be appreciated. |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Can I take care of formatting so it ends up as March 12, 2005 in your code
vs. in the spreadsheet? Assuming the address of the cell you saving the date to is hardcoded, manually format the cell to display the date as required, no need to do it each time in the Save event (providing user hasn't changed it). Or if needs, with code myCell.NumberFormat = "mmmm dd, yyyy" Regards, Peter T "David" wrote in message ... Thanks Peter, yours seems to have worked best of all the solutions I received. The others may have worked just as well if I knew more about VB. Can I take care of formatting so it ends up as March 12, 2005 in your code vs. in the spreadsheet? Thanks again for your help. "Peter T" <peter_t@discussions wrote in message ... Hi David, in the ThisWorkbook module - Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _ Cancel As Boolean) 'if don't want date if no changes since last save If ThisWorkbook.Saved = True Then Exit Sub On Error Resume Next Application.EnableEvents = False Worksheets("Sheet1").Range("A1") = Now Worksheets("Sheet1").Range("A2") = Date Application.EnableEvents = True End Sub Handy keyboard short cuts Ctrl ; semicolon - date with shift or colon - time Regards, Peter T PS FYI, my newsreader removed an attachment from your post it decided was unsafe. "David" wrote in message ... I have a need to automatically save the current date to a cell in an excel spreadsheet every time the sheet is saved. Today() always returns the current date, so once I open the sheet on a new day I can no longer see the date the information was last updated, i.e. saved. Any help would be appreciated. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
If cell is blank automatically enter today's date in the same cell | Excel Discussion (Misc queries) | |||
automatically enter today's date as a static entry in Excel | Excel Discussion (Misc queries) | |||
in excel how do enter today's date on a laptop | New Users to Excel | |||
Automatically enter today's date as a static entry | Links and Linking in Excel | |||
Automatically enter today's date as a static entry | Excel Worksheet Functions |