In VBA (Visual Basic for Applications), Environ$("username") is used to retrieve the username of the currently logged-in user in the Windows operating system. It returns a string containing the username associated with the Windows user account that is running the VBA code.
Example
Sub Get_User_Name()
'Getting username from computer
Dim sUserName As String
sUserName = Environ$("username")
Msgbox sUserName
'This will return the user that is currenlty being used
'Could also be found - C:\Users
End Sub
If a function is required
Example
Public Function Get_User_Name() As String
'Getting username from computer
Dim sUserName As String
sUserName = Environ$("username")
Get_User_Name = sUserName
End Function