PDA

View Full Version : Lock record creation in Excel



FotoFan
09-17-2007, 03:16 PM
I'm new at Vb so please be gentle...

I need to create a date and time "serial Number" in Excel that will not change when the document is opened a second time. If I use the =NOW() function, the date will be auto entered but will change when I reopen the doc later. How do I lock this so once it is entered, it will remain as a record of when the doc was saved?

Thanks

Bob Phillips
09-17-2007, 03:22 PM
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
With Worksheets("Sheet1").Range("A1")
.Value = Now
.NumberFormat = "dd-mmm-yyyy hh:mm:ss"
End With
End Sub

Private Sub Workbook_Open()

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