Get current user name

For a computer that is not joined to a domain (Computer Username)

Sub Get_Username()

'Get the environment username

Dim UserName As String

UserName = Environ$("UserName")

MsgBox "Hello " & UserName

End Sub

For a computer that is joined to a domain (Domain Display Name)

Sub Get_DomainDisplayName()

'Get the environment username

Dim UserName As String, DisplayName As String

UserName = Environ$("UserName")

'Get the displayname

Dim objAllNames As Object

On Error Resume Next

Set objAllNames = GetObject("Winmgmts:").instancesof("win32_networkloginprofile")

For Each objIndName In objAllNames

If objIndName = UserName Then

DisplayName = objIndName.FullName

End If

Next

MsgBox "Hello " & DisplayName

End Sub