![]() |
Function to display username/networkname
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 |
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 |
Function to display username/networkname
Thanks Chris, works perfectly!
"Chris" wrote: 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 |
Function to display username/networkname
I might be pushing this a bit, but I'd like to record the date and time the
user previously opened the workbook. A1=The username function you provided. =IF(A1="Username1",NOW(),"Unknown") This formula records the time when the file is openend. However, whenever this user makes a change and the workbook is recalculated, the "NOW" time is updated. Also, when "Username2" opens the workbook, the formula for "Username1" will change to "Unkown" Would you have any thoughts on how to "freeze" the formula? I understand if this is asking too much :) Regards, Hendrik "Chris" wrote: 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 |
Function to display username/networkname
Just another way:
Public Function ReturnNetworkName() As String ReturnNetworkName = Environ("UserName") End Function HTH "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 |
All times are GMT +1. The time now is 05:30 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com