Get data from Active Directory

D

Dominique Heyler

Hi,



Do you know an easy way to get hold of the user information stored in AD
using VBA. I don't find any documentation online or in my help files about
the syntax or the libraries I should use.



:) Dominique
 
P

Perry

Use LDAP.
Google for VBA and LDAP and y'll get a multitude of options
Here's one example straight from a google search quest (using above key
words)

Krgrds,
Perry

Dim con As ADODB.Connection
Dim com As ADODB.command
Dim rs As ADODB.Recordset


Dim ADsPath As String
ADsPath =
"LDAP://directorydev.domain.com/aid=it0030,ou=Applications,o=domain.com,c=us"
'set the connection
Set con = New ADODB.Connection
With con
.Provider = "ADSDSOObject"
'.Properties("User ID") = "cn=Directory Manager"
',aid=it0030,ou=Applications,o=domain.com,c=us"
'.Properties("Password") = "password"
.Open "ADSI"
End With

'set the command object
Set com = New ADODB.command
With com
.ActiveConnection = con
.CommandText = "<" & ADsPath &
">;(userreferencedn=*xternal*);ADsPath;subtree"
End With

Set rs = com.Execute

If Not (rs.BOF And rs.EOF) Then
rs.MoveLast
rs.MoveFirst
MsgBox rs.RecordCount & "'s Returned"
While Not rs.EOF
MsgBox rs.Fields(0).Value
rs.MoveNext
Wend
End If

con.Close
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top