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):
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?
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?