Windows username in VBA

I would like to know how I can access the Windows username in VBA, I mean the username that appears in this image below:

enter image description here

I give this accuracy because I tried using it Environ("Username"), but it gives a login that I have to enter in order to launch windows that are different from the name that I want.

+4
source share
1 answer

You should be able to use this function:

Public Function GetUserDisplayName() As String
    GetUserDisplayName = GetObject("LDAP://" & CreateObject("ADSystemInfo").UserName).DisplayName
End Function
+4
source

Source: https://habr.com/ru/post/1599287/


All Articles