UserName Property Example (from HELP) This example displays the name of the current user. MsgBox "Current user is " & Application.UserNameWhich displays the name as it exists in Tools, Options, General, User Name:
Declare Function GetComputerName& Lib "kernel32" Alias "GetComputerNameA" (ByVal lbbuffer As String, nsize As Long) Function returnname() Dim z As String * 64 Call GetComputerName(z, 64) returnname = z End Function
Private Declare Function apiGetUserName Lib "advapi32.dll" _
    Alias "GetUserNameA" (ByVal lpBuffer As String, nsize As Long) As Long
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If lngX <> 0 Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = ""
    End If
End Function
Sub PCInformation()
 Dim msg  'David McRitchie, 2002-07-11, misc
 msg = "UserName" & vbTab & Environ$("username") & vbNewLine _
  & "UserProfile" & vbTab & Environ("UserProfile") & vbNewLine _
  & "Computer #" & vbTab & Environ$("ComputerName") & vbNewLine _
  & "Logon Server" & vbTab & Environ$("Logonserver") _
  & vbNewLine & "UserDomain " & vbTab & Environ$("UserDomain")
 MsgBox msg, , "Environment Variables"
End Sub
Visit [my Excel home page] [Index page] [Excel Onsite Search] [top of this page]
Please send your comments concerning this web page to: David McRitchie send email comments
Copyright © 1997 - 2004, F. David McRitchie, All Rights Reserved