otus
otus

Reputation: 385

Windows username in VBA

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 :

enter image description here

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

Answers (1)

Rory
Rory

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

Related Questions