ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Active Directory and UserName (https://www.excelbanter.com/excel-programming/319347-active-directory-username.html)

augustus

Active Directory and UserName
 
Hi,

I was wondering, is there way to retrieve the Display Name as shown under
Active Directory, from VBA if the only available info is the logon Username?

I'm running Windows2000 & above, Office 2000, Server2003 Std.

Thanks
Augustus

Jim Thomlinson[_3_]

Active Directory and UserName
 
Here is the NT username. Not sure if this is what you want, but I think so...

Option Explicit


Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long


Public Function ReturnNTUserName() As String

' Returns the NT Domain User Name

Dim rString As String * 255, sLen As Long, tString As String
Dim NWUserName As String

tString = ""

On Error Resume Next
sLen = GetUserName(rString, 255)
sLen = InStr(1, rString, Chr(0))
If sLen 0 Then
tString = Left(rString, sLen - 1)
Else
tString = rString
End If
On Error GoTo 0

NWUserName = Left(Right(tString, Len(tString) - 1), Len(tString) - 2)
ReturnNTUserName = UCase(Left(tString, 1)) + NWUserName +
Right(UCase(tString), 1)

End Function



"augustus" wrote:

Hi,

I was wondering, is there way to retrieve the Display Name as shown under
Active Directory, from VBA if the only available info is the logon Username?

I'm running Windows2000 & above, Office 2000, Server2003 Std.

Thanks
Augustus



All times are GMT +1. The time now is 10:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com