Written by Allen Wyatt (last updated August 4, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003
When you are developing a worksheet, you may need to keep track of certain information about your workbook. For instance, you might want to place the creation date of a workbook into a cell. While Excel does provide some worksheet functions for dates (such as NOW or TODAY), it does not provide a worksheet function to access the workbook creation date.
This means that the answer lies in using a macro. For instance, you might create a macro that would determine the current date and input it (as text) into a particular cell. This macro could then be run whenever you created a new workbook by naming the macro Auto_Open. The following is an example of such a macro:
Sub Auto_Open() If Worksheets.Application.Range("A1") = "" Then Worksheets.Application.Range("A1") = Format(Date, "long Date") End If End Sub
The macro checks to see what is in cell A1. If there is nothing there, then it puts the text version of today's date in there. If there is something already there (which there would be every time you subsequently open the workbook), then the information is left intact and unscathed.
Perhaps the most satisfactory approach, however, is to actually access the operating system and pull the file creation date for the current workbook. This can be done with the following macro function:
Function CreateDate() As String Dim Temp As String On Error GoTo NoFile Temp = CreateObject("scripting.filesystemobject"). _ GetFile(ActiveWorkbook.Name).dateCreated CreateDate = Left(Temp, InStr(Temp, " ") - 1) GoTo Done NoFile: CreateDate = "Not Saved" Done: End Function
Notice that this approach isn't tied to a particular cell in your worksheet. To use the macro, simply put the following in any cell of your worksheet:
=CreateDate()
The function returns either "Not Saved" (if the workbook is brand new and hasn't been saved before) or it returns a text value that represents the date on which the workbook was created.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2367) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Noting the Workbook Creation Date.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
If someone sends you a worksheet that has lots of data in it, you might want to "spread out" the data so you can have ...
Discover MoreNeed a way, in a macro, to convert binary numbers into their decimal equivalents? There are two ways you can get the ...
Discover MoreWhen your macro is processing information in a worksheet, do you need to periodically make the contents of a cell bold? ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2018-08-12 06:45:16
Willy Vanhaelen
By reading this tip I became curious to know the creation date of some of my workbooks. I started to experiment and found out that the creation date returned by FileSystemObject (Windows) used in this tip's UDF is not reliable. When you copy a file, Windows shows the copy date as creation date. When you continue working with the copy you get a false creation date. So I did some more investigation and discovered that Excel keeps record of the real creation date. This can be accesses through vba with BuiltinDocumentProperties("Creation Date").
So I inserted a macro in my personal macro collection:
Sub Created()
MsgBox ActiveWorkbook.BuiltinDocumentProperties("Creation Date"), , "Creation date of active file"
End Sub
Having assigned a shortcut key for this macro I can find out the creation date of any open workbook in the blink of an eye, eliminating the need of any UDF associated with a formula somewhere in a worksheet.
If you prefer to use one of the macros of this tip, you can drastically simplify them by using
BuiltinDocumentProperties.
Sub Auto_Open() 'or better: Private Sub Workbook_Open()
Worksheets(1).Range("A1") = ActiveWorkbook.BuiltinDocumentProperties("Creation Date")
End Sub
No need to check if A1 already has a date because it won't change.
Function CreateDate()
CreateDate = ActiveWorkbook.BuiltinDocumentProperties("Creation Date")
End Function
If you enter =CreateDate() in a brand new workbook that hasn't been saved before, the current date is displayed, so there is no need for error catching.
Format the cell containing the creation date to your liking.
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments