Written by Allen Wyatt (last updated February 20, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
Laurie knows how to view properties of an Excel workbook. What she would like to do, however, is to view similar properties relative to individual worksheets. For instance, she wonders if there is a way to view properties such as date created, date modified, author, or "last modified by" for individual worksheets.
Unfortunately, Excel doesn't keep track of such information for worksheets. The only workaround we've been able to figure out is to develop your own record of information about the worksheets in the workbook. An obvious way to do develop a Workbook_SheetChange event handler. The following is an example of one you could add to the ThisWorkbook object in the Visual Basic Editor:
Private Sub Workbook_SheetChange(ByVal ws As Object, ByVal Target As Range) Dim s As Worksheet Dim J As Integer Dim FoundIt As Boolean On Error Resume Next Set s = Worksheets("Stats") On Error GoTo 0 Application.EnableEvents = False If s Is Nothing Then ' Stats worksheet did not exist Set s = Worksheets.Add(After:=Worksheets(Worksheets.Count)) s.Name = "Stats" s.Range("A1") = "Worksheet" s.Range("B1") = "Creator" s.Range("C1") = "Last Modified" s.Range("D1") = "Modifed By" With s.Range("A1:D1") .Font.Bold = True .Borders(xlEdgeBottom).LineStyle = xlContinuous .Borders(xlEdgeBottom).Weight = xlThin End With s.Range("A2") = s.Name s.Range("B2") = s.CustomProperties.Creator s.Range("C2") = Format(Now, " mm/dd/yyyy hh:mm am/pm") s.Range("D2") = Application.UserName End If J = 2 FoundIt = False While (s.Cells(J, 1) <> "") If s.Cells(J, 1) = ws.Name Then FoundIt = True s.Cells(J, 3) = Format(Now, " mm/dd/yyyy hh:mm am/pm") s.Cells(J, 4) = Application.UserName End If J = J + 1 Wend If Not FoundIt Then ' Worksheet name not found s.Cells(J, 1) = ws.Name s.Cells(J, 2) = ws.CustomProperties.Creator s.Cells(J, 3) = Format(Now, " mm/dd/yyyy hh:mm am/pm") s.Cells(J, 4) = Application.UserName End If ws.Activate Application.EnableEvents = True End Sub
The event handler is triggered anytime you make a change in the workbook. It first checks to see if there is a worksheet named Stats. If not, then the worksheet is created, and some rudimentary information is added to it. The handler looks in the Stats worksheet to determine if the data there includes a row for the worksheet on which a change occurred. If not, then a row is added, but if so, the information in the row is updated.
The handler only tracks four pieces of information—the worksheet name, the creator, the date the last change was made, and the user name of who made the change. (The Creator property indicates a numeric value related to the program that created the worksheet. It isn't terribly helpful for humans, and I included it as an illustrative example of how information can be stored.)
Remember, this is only a workaround and you should consider carefully what type of information you want to track for your worksheets. You can then modify the code to reflect that desire.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7542) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!
If you want someone to not be able to move from one worksheet to another in a workbook, you've got your work cut out for ...
Discover MoreIf you need to work on two worksheets in the same workbook at the same time, Excel makes this rather easy to do. All you ...
Discover MoreExcel makes it relatively easy to copy worksheets to a different workbook. That doesn't mean it couldn't be made simpler ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2019-04-15 04:45:47
David Shepherd
The current user's username can be captured using the Environ function:
Dim sName As String
sName = Environ("UserName")
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