So, I've cribbed some VBA code to pull the login name of the user into a workbook. (I readily admit that I copied this from another site, as I really have no clue when it comes to VBA.)

This code works a treat for getting the username, and I simply add the formula "=windowsusername()" into whatever cell I want to have it populate.

However, if a different user opens the worksheet, it then changes the result. (That is, if "aliceanders" opens the doc first, then saves it and send it to "bobbrewer", when Bob opens it, the user will be "bobbrewer".)

Question: how can I get this to only update the cell the first time someone opens the document?

The VBA I'm using:

Option Explicit
 'api call for obtaining the username
Private Declare Function GetUserName& Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long)
 
Public Function WindowsUserName() As String
     '   ---------------------------------------------
     '   Function to extract the name:
     '   ---------------------------------------------
    Dim szBuffer As String * 100
    Dim lBufferLen As Long
     
    lBufferLen = 100
     
    If CBool(GetUserName(szBuffer, lBufferLen)) Then
         
        WindowsUserName = Left$(szBuffer, lBufferLen - 1)
         
    Else
         
        WindowsUserName = CStr(Empty)
         
    End If
     
End Function