Good afternoon. I have seen a few posts that half answer this question, but none quite go the whole way...
I have found the code below which helpfully returns the username of the person executing it. What I would like to do now is filter the rows where the username matches the contents of Column B in Sheet1 of my spreadsheet.
Any thoughts would be most welcome.
Thanks
I have found the code below which helpfully returns the username of the person executing it. What I would like to do now is filter the rows where the username matches the contents of Column B in Sheet1 of my spreadsheet.
Any thoughts would be most welcome.
Thanks
Code:
Option Explicit
Sub Users_Fullname()
Dim objInfo
Dim strLDAP
Dim strFullName
Set objInfo = CreateObject("ADSystemInfo")
strLDAP = objInfo.UserName
Set objInfo = Nothing
strFullName = GetUserName(strLDAP)
MsgBox "Full name of User is " & strFullName 'step to test
End Sub
Function GetUserName(strLDAP)
Dim objUser
Dim strName
Dim arrLDAP
Dim intIdx
On Error Resume Next
strName = ""
Set objUser = GetObject("LDAP://" & strLDAP)
If Err.Number = 0 Then
strName = objUser.Get("givenName") & Chr(32) & objUser.Get("sn")
End If
If Err.Number <> 0 Then
arrLDAP = Split(strLDAP, ",")
For intIdx = 0 To UBound(arrLDAP)
If UCase(Left(arrLDAP(intIdx), 3)) = "CN=" Then
strName = Trim(Mid(arrLDAP(intIdx), 4))
End If
Next
End If
Set objUser = Nothing
GetUserName = strName
End Function