A
AmyAnders
Can someone help me understand the proper way to use the
"Workbook_BeforeSave" or "Workbook_BeforeClose" functions?
I would like to be able to save the current time and date into
my worksheet. When I 'step through' the code using F8, it
works fine. However, when I close or save the file, I would
expect "Workbook_BeforeSave" or "Workbook_BeforeClose" to
do something, correct? I have tried both of these, and saved
the file manually; as well as closing Excel and saving the file when
prompted. When I reopen the file though, there are still is no
date or no time displayed in the cells.
Here's my code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel A
Boolean)
DateTime
End Sub
Sub DateTime()
Dim rng_date As Range
Dim rng_time As Range
Set rng_date = Worksheets("Sheet1").Range("E2")
Set rng_time = Worksheets("Sheet1").Range("B2")
rng_date.Value = Format(Date, "dd-mmm-yyyy")
rng_time.Value = Format(Time, "hh:mm")
End Sub
By the way, I am using Excel 2003 and WinXP.
Thanks in advance,
Am
"Workbook_BeforeSave" or "Workbook_BeforeClose" functions?
I would like to be able to save the current time and date into
my worksheet. When I 'step through' the code using F8, it
works fine. However, when I close or save the file, I would
expect "Workbook_BeforeSave" or "Workbook_BeforeClose" to
do something, correct? I have tried both of these, and saved
the file manually; as well as closing Excel and saving the file when
prompted. When I reopen the file though, there are still is no
date or no time displayed in the cells.
Here's my code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel A
Boolean)
DateTime
End Sub
Sub DateTime()
Dim rng_date As Range
Dim rng_time As Range
Set rng_date = Worksheets("Sheet1").Range("E2")
Set rng_time = Worksheets("Sheet1").Range("B2")
rng_date.Value = Format(Date, "dd-mmm-yyyy")
rng_time.Value = Format(Time, "hh:mm")
End Sub
By the way, I am using Excel 2003 and WinXP.
Thanks in advance,
Am