finding a user in active directory using vba

Hackepeter

New Member
Joined
Feb 22, 2012
Messages
2
Hi Folks,

I've tried various searches in this and other forums. Nothing helped me out with my problem. So I'm asking YOU :cool:.
I use Excel 2007.

the background:
we have a bigger AD with more than only one hirarchical level in ad.
I need to find a user with a given "sAMAccountName".
I don't know where his entry is located in the tree.
as example my user's path is:
OU=06,OU=Users,DC=domain,DC=com

others are located in other groups in group "Users". There are about 90 subgroups in this section.

What I can do ist to walk down in 2 loops from root through every object in these groups. But this can´t be the solution.

What I want is to "search" the AD and find the correct entry and it's path.
something like
search "me" in AD
returning the object "me" for accessing the needed parameters (me.name...) or me.member (which is another task why I want to have this code as generic as possible)

What I have now:
Code:
Sub test()   ' will be a function later on if working

Dim colOU As IADsContainer
Dim strName as String    ' --> I use a fixed value of the sAMAccountName for testing this
Dim sAUFRUF As String


strName = "userid"
    sAUFRUF = "LDAP://DC=domain, DC=com, sAMAccountName=" & strName


Set colOU = GetObject(sAUFRUF)  ' --> :crash:


    Debug.Print colOU.Name
    Debug.Print colOU.AccountExpirationDate
I will get an Error -2147016672 saying somthing crytic.

There must be a mistake in syntaxing the value of sAUFRUF. I'm german...

Can you hepl me?

thanks
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,216,126
Messages
6,129,020
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top