You will need to change the sheet names in the code below. Currently the code logs each user to Sheet2 in the Workbook. It logs:
User ID , Date, Time
One user to a row, newest user at the bottom of the list, each time the WorkBook is opened.
Private Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" _
(ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long
'ThisWorkbook code!
Private Const NO_ERROR = 0&
Private Const ERROR_MORE_DATA = 234&
Private Const ERROR_NO_NETWORK = 1222&
Private Const ERROR_NOT_CONNECTED = 2250&
Private Const ERROR_EXTENDED_ERROR = 1208&
Private Const ERROR_NO_NET_OR_BAD_PATH = 1203&
Private Sub Workbook_Open()
'ThisWorkbook code only!
Dim myClrBuffer$, myUser$, logedUser$, myErrTag$
Dim userStatus&
myClrBuffer = Space$(255)
userStatus = WNetGetUser("", myClrBuffer, 255)
If userStatus = 234 Then myErrTag = "ERROR_MORE_DATA"
If userStatus = 1222 Then myErrTag = "ERROR_NO_NETWORK"
If userStatus = 2250 Then myErrTag = "ERROR_NOT_CONNECTED"
If userStatus = 1208 Then myErrTag = "ERROR_EXTENDED_ERROR"
If userStatus = 1203 Then myErrTag = "ERROR_NO_NET_OR_BAD_PATH"
If userStatus = NO_ERROR Then
myUser = Left(myClrBuffer, InStr(myClrBuffer, vbNullChar) - 1)
logedUser = logedUser & "User: " & myUser & ", on: " & Date & ", at: " & Time
Sheets("Sheet2").Range("A1").Value = "Logged Users!"
Sheets("Sheet2").Range("A1").Font.Bold = True
Sheets("Sheet2").Range("A65536").End(xlUp).Offset(1, 0).Value = logedUser
Else
Sheets("Sheet2").Range("A1").Value = "Logged Users!"
Sheets("Sheet2").Range("A1").Font.Bold = True
Sheets("Sheet2").Range("A65536").End(xlUp).Offset(1, 0).Value = myErrTag & ", " & _
"User: " & myUser & ", on: " & Date & ", at: " & Time
End If
Sheets("Sheet2").Select
Sheets("Sheet2").Range("A65536").End(xlUp).Offset(0, 9).Select
Sheets("Sheet1").Select
Sheets("Sheet1").Range("A1").Select
End Sub