Last Modified

G

Guest

I am looking for a way for excel to auto add the last modified date and time
as well as the user. I would like the date and time in one cell and the user
in a seperate cell. Is this something that can be done fairly easily? Any
help is always appreciated.

Thanks,
Steve
 
G

Guest

You will need VBA for this. Copy the following into a VBA code module, to get
the user's ID from the network (not guaranteed to work on every kind of
network):

'Declare API functions
Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
(ByVal lpBuffer As String, nSize As Long) As Long

Public Function ReturnUserName() As String
'Returns the NT Domain User Name
Dim rString As String * 255, sLen As Long, tString As String
tString = ""
On Error Resume Next
sLen = GetUserName(rString, 255)
sLen = InStr(1, rString, Chr(0))
If sLen > 0 Then
tString = Left(rString, sLen - 1)
Else
tString = rString
End If
On Error GoTo 0
ReturnUserName = UCase(Trim(tString))
End Function

In the ThisWorkbook module, add a Workbook_BeforeSave event routine like the
following:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Range("A4").Value = Now()
Range("A5").Value = ReturnUserName()
End Sub

Hope this helps,

Hutch
 

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

Top