Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Noting When a Workbook was Changed.
Written by Allen Wyatt (last updated March 29, 2021)
This tip applies to Excel 2007, 2010, and 2013
In an environment where multiple people work on the same workbook, you may want a way to keep track of when people last changed a workbook. There are a couple of ways you can approach this task. One is to simply figure out when a workbook was last saved. This approach works well if you assume that any changes to the workbook are always saved. (Unsaved changes, of course, are not really a lasting change at all.) The following macro returns the date that a workbook was saved and stores that date in cell A1:
Sub DateLastModified() Dim fs, f Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFile("D:\MyFolder\MyFile.xlsx") Cells(1, 1) = f.DateLastModified End Sub
To use the macro, just replace the D:\MyFolder\MyFile.xlsx file specification with whatever is appropriate for you.
If you want a history sheet of who did what with your workbook, then a different approach is necessary. Perhaps the best solution is to try Excel's sharing feature, which can be configured to keep a history log for a workbook. Follow these steps:
Figure 1. The Editing tab of the Share Workbook dialog box.
Figure 2. The Advanced tab of the Share Workbook dialog box.
As changes are made to the workbook, Excel tracks those changes (along with who made them) and puts them in a separate worksheet so you can review them later.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7924) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Noting When a Workbook was Changed.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
If you try to open a workbook that someone else has open, Excel lets you know of the conflict. What if Excel tells you, ...
Discover MoreSalvaging information from a corrupted workbook can be a lot of work. This tip looks at how you can approach the problem ...
Discover MoreExcel has the capability to automatically open workbooks when you first start the program. You may not want to have one ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-04-01 12:50:03
J. Woolley
@Norm Thibodeau
You might try the following refinement of your workbook event macro:
Private LastChanged As Date ' initially zero
Const TheSheet = "Sheet1", TheCell = "A1"
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Sh Is Worksheets(TheSheet) And Target Is Range(TheCell) Then Exit Sub
LastChanged = Now
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If LastChanged > 0 Then Worksheets(TheSheet).Range(TheCell).Value = LastChanged
End Sub
Also, see https://sites.google.com/view/MyExcelToolbox/
2021-03-29 09:58:44
Norm Thibodeau
Oops - error in my previous post is corrected below. Changed "BeforePrint" to "BeforeSave" as the event to trigger the Sub.
Last changed date is important to me as a project manager. So I usually keep a Last Saved date on my worksheet.
I think an easier way is to just pull the last saved value from the document properties:
Range("$A$1").Value = ActiveWorkbook.BuiltinDocumentProperties.Item("Last Save Time")
Or, an automatic approach is to use a workbook event macro to populate it from Now() whenever the workbook is saved.
Private Sub Workbook_BeforeSave(Cancel As Boolean)
Range("$A$1").Value = Now()
End Sub
Unfortunately, all of these must assume that the workbook would not be saved unless it was changed. That's usually a valid assumption, but it's not guaranteed. Anyone can do a save on the workbook without having changed anything.
Wouldn't it be nice if Excel provided access to file metadata as a worksheet function? In MS Word, the file metadata is available in fields and you can add those fields to your text wherever you'd like.
2021-03-29 09:54:50
Norm Thibodeau
Last changed date is important to me as a project manager. So I usually keep a Last Saved date on my worksheet.
I think an easier way is to just pull the last saved value from the document properties:
Range("$A$1").Value = ActiveWorkbook.BuiltinDocumentProperties.Item("Last Save Time")
Or, an automatic approach is to use a workbook event macro to populate it from Now() whenever the workbook is saved.
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Range("$A$1").Value = Now()
End Sub
Unfortunately, all of these must assume that the workbook would not be saved unless it was changed. That's usually a valid assumption, but it's not guaranteed. Anyone can do a save on the workbook without having changed anything.
Wouldn't it be nice if Excel provided access to file metadata as a worksheet function? In MS Word, the file metadata is available in fields and you can add those fields to your text wherever you'd like.
2017-08-31 15:52:19
Yvan Loranger
Another way to figure out when a workbook was last saved is to use Windows.
Open the Start button, choose Computer and drill down into whatever drive & folders house your workbook.
2017-08-31 09:47:10
Allen
Melanie: When DIM is used without a data type, VBA defaults to declaring the variable as a Variant.
-Allen
2017-08-31 09:32:18
melanie
Hi,
I'm fairly new to the world of VBA so please excuse me if this sounds stupid.
I don't understand why "Dim" is used as shown above. It's not really being used to declare the variable type, e.g., "Dim fs as string", so why have it?
I suspect the Dimension statement defaults to something, but what?
Thanks,
Melanie
2017-08-31 08:39:48
Yvan Loranger
Another way to figure out when a workbook was last saved is to use Windows.
Open the Start button, choose Computer and drill down into whatever drive & folders house your workbook.
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments