Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting fullname from ad in VBA 1

Status
Not open for further replies.

ocb

IS-IT--Management
Nov 5, 2003
78
0
0
NO
Hi

I'm working on a Excel workbook with users from ad, sorted by username.

Is there any quick programming code I can use to get the fullname and the ou out from VBA to put in cells beside the username? I was thinking that a short function with the username as input might get the fullname or the ou as output, but I never did any VB programming against active directory before.

Anyone who could see? Is there a chance to make Excel/VBA talk to AD and get out the full name and ou?

Thx
 




Hi,

Not everyone is knows your acronyms, including me.
Code:
msgbox thisworkbook.fullname
Also on the sheet, without VBA...
[tt]
=CELL("filename")
[/tt]




Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I did not mean the workbook's name, but a list of users in our domain.

If I have a list of usernames in column A, I would list their Fullname in column B..
 



AD?
ou?

Wa???

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Windows environment.

AD=Active Directory
OU=Organizational Unit

Things on a Windows Server...
 
Please search forum before posting: Search on "Query AD" pulled this up as the 1st result:

thread707-1505845

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
I use something like this.

Code:
Sub finduser()

Dim User As ActiveDs.IADsUser
dim domainname as string
domainname = "somewhere.co.uk"
Set User = GetObject("WinNT://" & domainname & "/" & Range("a1").Value & ",user")
        
        If Err.Number <> 0 Then
        Status.Text = "Domain or User does not exist."
        Exit Sub
        End If
        

MsgBox User.FullName
End Sub

don't forget to add a reference to the "Active DS Type Library".



Hope this helps.

Matt
[rockband]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top