How To Display Current User "FULL NAME" in cell.

Blueridge227

New Member
Joined
Mar 23, 2011
Messages
29
I have tried the following functions:

-Environ("UserName")
-Application.username

But both only display the first letter of the first name and then the last name. eg "jsmith"

Is there a way to display the users full name as it is in active directory. eg "John Smith"
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Do you know where the full name is stored on the PC. The following code will list all the Environ Commands and if you run it in the VBA Screen with the Debug window open (Ctrl + G) then it might show you a command that you could use.

Code:
Sub GetEnvironVariables()
     '   ---------------------------------------------------------
     '   List all the available Environ information
     '   Environ Function returns info about the operating system
     '   Info will be listed in the Immediate Window (Ctrl+G)
     '   ---------------------------------------------------------
    If Application.VBE.MainWindow.Visible = False Then
         '   ---------------------------------------------------------
         '   To ensure you see the result, I used SendKeys to open
         '   the vbe, and then display the Immediate Window
        SendKeys "%{F11}", True
        SendKeys "^g", True
        GoTo RunProc
         '   ---------------------------------------------------------
    Else
RunProc:
        Dim i As Integer
        i = 1
        While Environ(i) <> Empty
            Debug.Print Environ(i)
            i = i + 1
        Wend
    End If
End Sub
 
Upvote 0
i use the following in vbscript, just adapted it and made it a function for VBA, needs testing as I am not on a network with AD at the moment, refer to it in a cell as =myusername

Code:
public function myUserName() as string
dim objNetwork as Object
Set objNetwork = CreateObject("WScript.Network")
myUsername = objNetwork.UserName
set objNetwork = nothing
end function
 
Upvote 0
Thank you for your replies. I have directed users to change the way their office user names display by doing the following, File > Options > General > Personalize your copy of office > Username.

The application.username function then works properly. I will try your suggestions as I still want to come up with a better solution that won't depend on how office was installed on their machines.
</SPAN></SPAN>
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,366
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top