Examples for Visual Basic for Application accessing the Windows API: GetUserName
The Windows API function GetUsername finds the name of the user that is associated with the current thread.
The following example needs the VBA declarations of the Windows API which can be found here.
option explicit
sub main()
dim userName as string * 32
dim result as long
result = GetUserName(userName, 32)
if result <> 0 then
msgBox "The currently logged in user is " & userName
else
msgBox "Calling GetUserName failed"
end if
end sub