Macro to Record date workbook is first opened

  • Thread starter Thread starter darkeh
  • Start date Start date
D

darkeh

I need help with writing a macro or formular that will record the firs
date a workbook is open
 
Private Sub Workbook_Open()
Dim rng as Range
set rng = ThisWorkbook.Worksheets("Sheet1").Range("A1")
if isempty(rng) then
rng.Value = Date + Time
rng.Numberformat:= "mm/dd/yyyy hh:mm:ss"
rng.EntireColumn.Autofit
End if
end Sub

Not sure what the situation is, but while this will write the date and time
in the cell, the workbook must be saved as well. You might want to prompt
for a path and filename at this time and save the file.

Put a macro like the above in the ThisWorkbook Module.

Chip Pearson's page on Events

http://www.cpearson.com/excel/events.htm
 
An alternative is to put the value in a workbook name if you don't want to
show on a worksheet.

--

HTH

RP

Tom Ogilvy said:
Private Sub Workbook_Open()
Dim rng as Range
set rng = ThisWorkbook.Worksheets("Sheet1").Range("A1")
if isempty(rng) then
rng.Value = Date + Time
rng.Numberformat:= "mm/dd/yyyy hh:mm:ss"
rng.EntireColumn.Autofit
End if
end Sub

Not sure what the situation is, but while this will write the date and time
in the cell, the workbook must be saved as well. You might want to prompt
for a path and filename at this time and save the file.

Put a macro like the above in the ThisWorkbook Module.

Chip Pearson's page on Events

http://www.cpearson.com/excel/events.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top