aideb
asked on
Lookup AD user from Excel spreadsheet
I am looking to return the user login name from a (long) list of user information I have in a spreadsheet.
I have the following information contained in the spreadsheet;
Full LDAP String of users e.g. LDAP://Server.domain.com/C N=Smith, John,OU= etc etc
GUID of users e.g. {123213-4324243432 etc
CN of users e.g. CN=Smith, John,OU= etc
I would like to be able to be able to run a macro on the column to return the user login name.
Can anyone suggest how this can be done?
I have the following information contained in the spreadsheet;
Full LDAP String of users e.g. LDAP://Server.domain.com/C
GUID of users e.g. {123213-4324243432 etc
CN of users e.g. CN=Smith, John,OU= etc
I would like to be able to be able to run a macro on the column to return the user login name.
Can anyone suggest how this can be done?
ASKER
Hi Dave,
I have tried this but get
System Error &H80040E37 (-2147217865)
This falls over at the following line.
Set adoRecordSet = AdoCommand.execute
I have tried this but get
System Error &H80040E37 (-2147217865)
This falls over at the following line.
Set adoRecordSet = AdoCommand.execute
ASKER
Dave,
The value in the cell is
CN=Stewart\, Bernadette,OU=FDS-CorpDC-U sers,OU=Lo ndon,OU=Co rp Users,OU=Corp,OU=Users,OU= User Accounts,DC=user,DC=ad,DC= company,DC =org,DC=uk
but I see that the strDNSDomain is being set to "CN=Stewart/DC=CN=Stewart" which doesn't look right?
Cheers
Aidan
The value in the cell is
CN=Stewart\, Bernadette,OU=FDS-CorpDC-U
but I see that the strDNSDomain is being set to "CN=Stewart/DC=CN=Stewart"
Cheers
Aidan
ASKER
Is anyone else able to offer any help?
Hi,
This looks like the full distinguished name rather than the common name. I will test the code at work tomorrow I'm in Oz :)
pls try
MsgBox
Get_LDAP_User_Properties
(
"user"
,
"distinguishedName
"
,
[
a1
].
Value
,
"samAccountName"
)
Cheers
Dave
ASKER
Still get the same error I'm afraid....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Now, that works!
Thanks for that. I will have a go at trying to get it to read in a column and outputting to another. I will let you know how I get on.
Cheers
Aidan
Thanks for that. I will have a go at trying to get it to read in a column and outputting to another. I will let you know how I get on.
Cheers
Aidan
ASKER
Modified the inital sub to traverse the column and output to another. Works a treat.
I am going to be running this on a number of other spreadsheets so I would like to be able to keep the workbook open which contains the macro and then run it on the workbook that has focus. I have seen that done before....any ideas how to do it?
Cheers
Aidan
I am going to be running this on a number of other spreadsheets so I would like to be able to keep the workbook open which contains the macro and then run it on the workbook that has focus. I have seen that done before....any ideas how to do it?
Cheers
Aidan
Sub Test()
Dim RowNumber As Range, RowTarget As Range
For Each RowNumber In Range("B:B").SpecialCells(xlCellTypeConstants)
RowNumber.Offset(0, 4).Value = Get_LDAP_User_Properties("user", "distinguishedname", RowNumber.Value, "samAccountName")
Next
End Sub
Hi Aidan
The code as is will run on the Activeworkbook and activesheet by default when it is run
I add all my frequentlty used codes to a workbook that I then save as an addin, so that they are automatically available in the background
Cheers
Dave
The code as is will run on the Activeworkbook and activesheet by default when it is run
I add all my frequentlty used codes to a workbook that I then save as an addin, so that they are automatically available in the background
Cheers
Dave
ASKER
hmmm for some reason it wont run like that.
I have placed the code in a module, assigned the macro to a shortcut key and saved it as an addin.
I have then opened another worksheet and added my new addin then executed the shortcut key. The code still reads from the previous data....any pointers?
Sorry, new to macros and addins.
I have placed the code in a module, assigned the macro to a shortcut key and saved it as an addin.
I have then opened another worksheet and added my new addin then executed the shortcut key. The code still reads from the previous data....any pointers?
Sorry, new to macros and addins.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That did the trick.....Many thanks!
ASKER
Fantastic....all working. Your help is much appreciated.
Cheers
Aidan
Cheers
Aidan
thx for the grade :)
Can you pls test if this code returns a valid login name for a user's common name - I af offline from my work connection so I can't test this function which I have brorrowed fro Rob Sampson. You will need to change the
[a1].Value
to the location of a common name in your file
If the code returns the login name as desired that I will update the main part of the excel code so that loops through all your common names.
Cheers
Dave
Open in new window