Hi

Ive got an issue with a get username function:

Private Declare Function WNetGetUser Lib "mpr.dll" Alias _
"WNetGetUserA" (ByVal lpName As String, ByVal lpUserName As String, _
lpnLength As Long) As Long
 
Private Const NO_ERROR = 0
Private Const ERROR_NOT_CONNECTED = 2250&
Private Const ERROR_MORE_DATA = 234
Private Const ERROR_NO_NETWORK = 1222&
Private Const ERROR_EXTENDED_ERROR = 1208&
Private Const ERROR_NO_NET_OR_BAD_PATH = 1203&
 
Function WinUsername() As String
 
Dim strBuf As String, lngUser As Long, strUn As String
strBuf = Space$(255) '//Clear buffer
lngUser = WNetGetUser("", strBuf, 255)
If lngUser = NO_ERROR Then
strUn = Left(strBuf, InStr(strBuf, vbNullChar) - 1)
WinUsername = strUn
Else
WinUsername = "Error :" & lngUser
End If
End Function
Now the above command will be used in a shared workbook and works for my user, but as soon as another user loads the workbook, the username stays the same and only works if the formula is deleted and re-typed.

Is there a way around this as I need the process to be fully automated.

Thanks in advance

A very confused Adam J