LDAP Issue Using Excel VBA

malibuman67

New Member
Joined
Oct 26, 2015
Messages
3
I am hoping someone on here is both an LDAP and Excel VBA expert as I am at a lost. I had some code that worked when we had an LDAP address with an open Port. However, the company has locked things down and has closed that Port and created a new Port that requires authentication credentials. I have tried and tried to get this to work, but to no avail. Here is the code (with some things marked out for security reasons) that worked with the "open Port" (636):

VBA Code:
Dim ADConn As Object 'LDAP connection
Dim iAdRootDSE As Object 'Root DSE
Dim strDefaultNamingContext As String 'AD Root Naming
Dim objCmd As Object 'ADODB Connection
Dim objDLRs As Object 'Result of LDAP Query
Dim strQuery As String 'LDAP Query String
Dim returnCN As Variant 'Hold primary email from query

Set ADConn = CreateObject("ADODB.Connection") 'Define ADODB Connection
ADConn.Provider = "ADsDSOObject" 'Get Provider

ADConn.Open "ADs Provider" 'Open AD Provider
strQuery = "<LDAP:// ldap.xxx.yyy.com:636/ou=people,o=xxx,c=us>;(a1=*abc*);cn"

Set objCmd = CreateObject("ADODB.Command")
objCmd.ActiveConnection = ADConn 'Define Connection
objCmd.Properties("SearchScope") = 2 'Search All
objCmd.Properties("Page Size") = 500 'Return up to 500 results

objCmd.CommandText = strQuery
Set objDLRs = objCmd.Execute

If Not (objDLRs.EOF) Then 'Result is not empty
     returnCN = objDLRs.Fields("cn").Value 'Get primary email
     MsgBox "CN = " & CStr(returnCN(0)), vbInformation, "Found CN"
End If 'Not (objDLRs.EOF)

I was told that I must now access the LDAP using something like this (non-Excel VBA terms): "ldaps://ldap.xxx.yyy.com:8636" -b 'ou=people,o=xxx,c=us' -D 'cn=FULL NAME,ou=people,o=xxx,c=us' -w 'User PWD' "filter criteria"

So, I tried the exact same VBA code above but with the following change:

ADConn.Open "ADs Provider", "cn=MYNAME,ou=people,o=xxx,c=us", MYPASSWORD 'Provide username and password"
strQuery = "<LDAP:// ldap.xxx.yyy.com:8636/ou=people,o=xxx,c=us>;(a1=*abc*);cn"

However, this has NOT worked. Does anyone know what I am doing wrong?
 
Hello! According to the rules of this forum, crossposting is prohibited.
Your duplicate post on another forum.
 
Upvote 0
Hello! According to the rules of this forum, crossposting is prohibited.
Your duplicate post on another forum.
OK...I thought the two forums were slightly different so it made sense to post the question on both. This site seems more general Excel whereas the other is more application (VBA) development. I was trying to increase the chances that someone, somewhere would/could answer.
 
Upvote 0

Forum statistics

Threads
1,226,837
Messages
6,193,249
Members
453,784
Latest member
Chandni

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