Does anyone know if it is possible to populate a cell with the users name from a network?
Does anyone know if it is possible to populate a cell with the users name from a network?
What I mean is can you pull the user name from the network and paste it into a cell?
I've usedon a domain based NT network to get the users login nameApplication.UserName
K :-)
Thanks.. I'll Try it
Application.Username gets the Applications default user name setup and not their loged on User name.
There are many ways to get this...here is one
Option Explicit Private Declare Function Get_User_Name _ Lib "advapi32.dll" _ Alias "GetUserNameA" ( _ ByVal lpBuffer As String, _ nSize As Long) _ As Long Private Function NTUserName() As String '// Returns the NT login username Dim lpBuff As String * 25 Get_User_Name lpBuff, 25 NTUserName = Left(lpBuff, Len(lpBuff) - 1) End Function Private Function NetworkUsername() '// Returns the (Network) Username from the Environment variables Dim str As String Dim i As Integer i = 1 '// looks for NWUSERNAME in environment variables Do Until Left(str, 10) = "NWUSERNAME" str = Environ$(i) i = i + 1 If i > 255 Then Exit Do Loop If i < 255 Then '// Just cuts off the first 11 characters ("NWUSERNAME=") NetworkUsername = Right(str, Len(str) - 11) Else NetworkUsername = "No Network Name" End If End Function
Kind Regards,
Ivan F Moala From the City of Sails
Hi Austen,
Another example, which doesn't require the API is in our Knowlege Base here
This function can be used to pull either the MS Office username, Windows Login name or the Computer Name.
HTH,
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
kpuls -
Thanks for the post. I incorporated this into a userform application.
Again - Thanks,
Kurt
Cheers, Kurt! Glad you found it useful!
Take care,
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!