• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Get Username in MsgBox

VARGEESH

Member
Hi,


I used the below code to display the current username while opening the workbook.

[pre]
Code:
Private Sub Workbook_open()

MsgBox "Hello " & Environ("Username") & "!", vbInformation, "Welcome Note"

End Sub
[/pre]

It's working fine. But it gets the userid instead of username.


E.g:

UserId: madasamv

Username: Vargeesh Madasamy


It displays "madasamv".


Please advise me.


Regards,

Vargeesh
 
Hi Vargesh,

Please check this out..!

[pre]
Code:
Sub Users_Fullname()
Dim objInfo
Dim strLDAP
Dim strFullName
Set objInfo = CreateObject("ADSystemInfo")
strLDAP = objInfo.UserName
Set objInfo = Nothing
strFullName = GetUserName(strLDAP)
MsgBox "Hello " & strFullName & "!", vbInformation, "Welcome Note"
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
[/pre]
 
Hi, Vargeesh!

Maybe this helps too:

http://chandoo.org/forums/topic/security-properties-of-a-cell

Regards!
 
Back
Top