View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chris Chris is offline
external usenet poster
 
Posts: 788
Default Function to display username/networkname

Try the following codes
Public Function GetUsername() As String

On Error Resume Next


Dim objScript As Object
Set objScript = CreateObject("WScript.NetWork")
If Not objScript Is Nothing Then
GetUsername = objScript.USERNAME
End If
Set objScript = Nothing


End Function
Public Function GetUserDisplayName() As String
'--------------------8<----------------------
Set oADSystemInfo = CreateObject("ADSystemInfo")
' get user object
Set oADsUser = GetObject("LDAP://" & oADSystemInfo.USERNAME)
' get full name of the current user
GetUserDisplayName = oADsUser.displayname
'--------------------8<----------------------
End Function

"Hendrik.Kleine" wrote:

I've been looking all over and I know it's possible, but I can't seem to
figure this one out.

I want Excel to display the Network name (windows logon ID) in a cell. I'd
like this to be a function, so I can do IF statements with it.

Any help greatly appriciated!
Hendrik