You can get the "Last Author" built in document property. This is the
User Name as entered in the "User name" item on the General tab of the
Options dialog (Tools menu, Options item). This can be changed by the
user, so while it may well suffice for most purposes, it shouldn't be
relied upon for security and audit purposes.
You could add a Custom Document Property containing the user's logon
ID. In the ThisWorkbook module, paste the following code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
On Error Resume Next
Dim CustomDocProps As Office.DocumentProperties
Set CustomDocProps = ThisWorkbook.CustomDocumentProperties
CustomDocProps.Add _
Name:="Last User ID", _
LinkToContent:=False, _
Type:=msoPropertyTypeString, _
Value:=Environ("UserName")
End Sub
This will create a custom property named "Last User ID" and give it a
value of the user's logon name. This property will be visible and
changeable in the Properties dialog (File menu, Properties), so the
dishonest user could circumvent it with a bit of effort.
Another way is to create a hidden defined name with the user's logon
ID.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
ThisWorkbook.Names.Add Name:="LastLogonID", _
RefersTo:=Environ("UserName"), _
Visible:=False
End Sub
This, too, could be circumvented by a skilled user. There really isn't
any fool-proof way to ensure that the UserName value can't be spoofed
by a skilled user. That said, any of these methods may well be "good
enough" for general use.
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)