Adapting Gary's code:
Private Sub Workbook_Open()
If Sheets("Sheet1").Range("A1").Value = "" Then
Sheets("Sheet1").Range("A1").Value = now()
End Sub
You are correct on your other post- if you are trying to save this as your
workbook name, you will probably need to eliminate any special characters
(I'd think the slashes in the date will also be problematic).
Consider the following option; although it isn't as easily readable (what
time is 1609 again?) this might work for you, and still allows you to easily
sort your directories. My PC defaults the hours parameter to military (24
hour) time, so I'd suggest testing it to make sure that it performs as
expected- so you don't have a 4pm file show up as 04xx instead of 16xx and
throw off the order
Private Sub Workbook_Open()
TimeText= Year(Now()) & Format(Month(Now), "00") & Format(Day(Now), "00") &
" " & Format(Hour(Now()), "00") & Format(Minute(Now()), "00")
If Sheets("Sheet1").Range("A1").Value = "" Then
Sheets("Sheet1").Range("A1").Value = TimeText
End Sub
"sam" wrote:
Hey Gary, I forgot to mention one thing.. I am going to save the file with
date and time stamp. But I dont want the value to update with current date
and time when I open any previous saved file. Sorry for the confusion before
Hope I made it clear
THanks in advance
"Gary''s Student" wrote:
The following Event macro will put the current date/time in cell A1 of Sheet1:
Private Sub Workbook_Open()
Sheets("Sheet1").Range("A1").Value = Now
End Sub
Because it is workbook code, it is very easy to install and use:
1. right-click the tiny Excel icon just to the left of File on the Menu Bar
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window
If you save the workbook, the macro will be saved with it.
To remove the macro:
1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
To learn more about Event Macros (workbook code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
--
Gary''s Student - gsnu200902
"sam" wrote:
Hi All,
Is there a way I can display Current Date & Time in a cell which updates
everytime I open the workbook?
Thanks in Advance