Reputation: 385
I would like to know how I can access the windows username in VBA, I mean the username that is displayed on this picture below :
I give this precision because I've tried using Environ("Username")
, but that gives the login that I have to enter to start windows which is different from the name I want.
Upvotes: 4
Views: 2178
Reputation: 34075
You should be able to use a function like this:
Public Function GetUserDisplayName() As String
GetUserDisplayName = GetObject("LDAP://" & CreateObject("ADSystemInfo").UserName).DisplayName
End Function
Upvotes: 4