ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Last Modified (https://www.excelbanter.com/excel-worksheet-functions/100413-last-modified.html)

Steve

Last Modified
 
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

Tom Hutchins

Last Modified
 
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

"Steve" wrote:

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



All times are GMT +1. The time now is 10:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com