![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | VBScript to search LDAP from Excel function? Hi! I have a VBScript that is working fine from cscript.exe, but I soon as I put it into an Excel Function, I'm always getting #NAME as result... what's wrong, do VBScript is limited when run from Excel? Here is the Excel function: Function ADUserLookup(cUser As String) Set adoCommand = CreateObject("ADODB.Command") Set ADOConnection = CreateObject("ADODB.Connection") ADOConnection.Provider = "ADsDSOObject" ADOConnection.Open "Active Directory Provider" adoCommand.ActiveConnection = ADOConnection strBase = "<LDAP://domain.com>" strFilter = "(&(objectCategory=person)(objectClass=user)(cn=" & cUser & "))" strAttributes = "sAMAccountName" strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" adoCommand.CommandText = strQuery adoCommand.Properties("Page Size") = 100 adoCommand.Properties("Timeout") = 30 adoCommand.Properties("Cache Results") = False Set adoRecordset = adoCommand.Execute If adoRecordset.EOF Then ADUserLookup = "False" Else ADUserLookup = "True" End If End Function I would like to use this function in a column where the fullname will come from another colunm: =aduserlookup( a2 ) What's wrong? Thanks. Claude Lachapelle Systems Administrator, MCSE |
My System Specs![]() |
| | #2 (permalink) |
| | Re: VBScript to search LDAP from Excel function? "Claude Lachapelle" <ClaudeLachapelle@xxxxxx> wrote in message news:288FF5C2-4604-46AA-BB9E-D34F7CF8D6FC@xxxxxx Quote: > Hi! > > I have a VBScript that is working fine from cscript.exe, but I soon as I > put > it into an Excel Function, I'm always getting #NAME as result... what's > wrong, do VBScript is limited when run from Excel? most obvious. But, that said, your function is not, strictly speaking, completely valid vbscript code. vbscript does not support the "as {type}" qualifier. Perhaps VBA does (that is the macro language of the office components). So, when you run this from cscript, what does it display for you? See another comment just past the end of your code. Quote: > Here is the Excel function: > > Function ADUserLookup(cUser As String) > > Set adoCommand = CreateObject("ADODB.Command") > Set ADOConnection = CreateObject("ADODB.Connection") > > ADOConnection.Provider = "ADsDSOObject" > ADOConnection.Open "Active Directory Provider" > adoCommand.ActiveConnection = ADOConnection > > strBase = "<LDAP://domain.com>" > strFilter = "(&(objectCategory=person)(objectClass=user)(cn=" & cUser & > "))" > strAttributes = "sAMAccountName" > strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" > > adoCommand.CommandText = strQuery > adoCommand.Properties("Page Size") = 100 > adoCommand.Properties("Timeout") = 30 > adoCommand.Properties("Cache Results") = False > > Set adoRecordset = adoCommand.Execute > > If adoRecordset.EOF Then > ADUserLookup = "False" > Else > ADUserLookup = "True" > End If > > End Function > > I would like to use this function in a column where the fullname will come > from another colunm: =aduserlookup( a2 ) > > What's wrong? routine will return either a value of "True" or "False" rather than some useful attribute of the account. Also, depending on the syntax of your "full name" attribute, it could be that it contains some character special to excel. Finally, perhaps VBA misreports a syntax error (i.e. the "as string" qualifier) by ignoring the definition of the function, thereby making the "=functionName" reference indicate the error indirectly. /Al Quote: > Claude Lachapelle > Systems Administrator, MCSE |
My System Specs![]() |
| | #3 (permalink) |
| | Re: VBScript to search LDAP from Excel function? "Claude Lachapelle" <ClaudeLachapelle@xxxxxx> wrote in message news:288FF5C2-4604-46AA-BB9E-D34F7CF8D6FC@xxxxxx Quote: > Hi! > > I have a VBScript that is working fine from cscript.exe, but I soon as I > put > it into an Excel Function, I'm always getting #NAME as result... what's > wrong, do VBScript is limited when run from Excel? > > Here is the Excel function: > > Function ADUserLookup(cUser As String) > > Set adoCommand = CreateObject("ADODB.Command") > Set ADOConnection = CreateObject("ADODB.Connection") > > ADOConnection.Provider = "ADsDSOObject" > ADOConnection.Open "Active Directory Provider" > adoCommand.ActiveConnection = ADOConnection > > strBase = "<LDAP://domain.com>" > strFilter = "(&(objectCategory=person)(objectClass=user)(cn=" & cUser & > "))" > strAttributes = "sAMAccountName" > strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" > > adoCommand.CommandText = strQuery > adoCommand.Properties("Page Size") = 100 > adoCommand.Properties("Timeout") = 30 > adoCommand.Properties("Cache Results") = False > > Set adoRecordset = adoCommand.Execute > > If adoRecordset.EOF Then > ADUserLookup = "False" > Else > ADUserLookup = "True" > End If > > End Function > > I would like to use this function in a column where the fullname will come > from another colunm: =aduserlookup( a2 ) > > What's wrong? > > Thanks. > > Claude Lachapelle > Systems Administrator, MCSE scripting language with various dialects for the various Microsoft Office applications). The scripting help file (script56.chm) has sections that discuss VBScript features not in Visual Basic for Applications and Visual Basic for Applications features not in VBScript. To find these sections, use the help file's table of contents like this: Windows Script Technologies -> VBScript -> User's Guide -> VBScript Features not in Visual Basic for Applications Perhaps someone else with better knowledge of both languages can point out your exact problem. -Paul Randall |
My System Specs![]() |
| | #4 (permalink) |
| | Re: VBScript to search LDAP from Excel function? The function below is from Excel, this is why I'm using "as String" in the Function declaration. BUT this is pure VBScript, and from what I'm understanding, Excel is supporting VBA, not VBScript... Now I have two choices; running an external VBScript which will open the ..xls file and replace what I need (looking if the user is existing in Active Directory) OR adapt this VBScript to respect VBA rules. Thanks. It seem that not all "Al Dunbar" wrote: Quote: > > "Claude Lachapelle" <ClaudeLachapelle@xxxxxx> wrote in > message news:288FF5C2-4604-46AA-BB9E-D34F7CF8D6FC@xxxxxx Quote: > > Hi! > > > > I have a VBScript that is working fine from cscript.exe, but I soon as I > > put > > it into an Excel Function, I'm always getting #NAME as result... what's > > wrong, do VBScript is limited when run from Excel? > Yes, there are some differences. The lack of the WSCRIPT object being the > most obvious. > > But, that said, your function is not, strictly speaking, completely valid > vbscript code. vbscript does not support the "as {type}" qualifier. Perhaps > VBA does (that is the macro language of the office components). > > So, when you run this from cscript, what does it display for you? > > See another comment just past the end of your code. > Quote: > > Here is the Excel function: > > > > Function ADUserLookup(cUser As String) > > > > Set adoCommand = CreateObject("ADODB.Command") > > Set ADOConnection = CreateObject("ADODB.Connection") > > > > ADOConnection.Provider = "ADsDSOObject" > > ADOConnection.Open "Active Directory Provider" > > adoCommand.ActiveConnection = ADOConnection > > > > strBase = "<LDAP://domain.com>" > > strFilter = "(&(objectCategory=person)(objectClass=user)(cn=" & cUser & > > "))" > > strAttributes = "sAMAccountName" > > strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" > > > > adoCommand.CommandText = strQuery > > adoCommand.Properties("Page Size") = 100 > > adoCommand.Properties("Timeout") = 30 > > adoCommand.Properties("Cache Results") = False > > > > Set adoRecordset = adoCommand.Execute > > > > If adoRecordset.EOF Then > > ADUserLookup = "False" > > Else > > ADUserLookup = "True" > > End If > > > > End Function > > > > I would like to use this function in a column where the fullname will come > > from another colunm: =aduserlookup( a2 ) > > > > What's wrong? > I'm not completely sure, but it seems odd to me that your ADUserLookup > routine will return either a value of "True" or "False" rather than some > useful attribute of the account. Also, depending on the syntax of your "full > name" attribute, it could be that it contains some character special to > excel. Finally, perhaps VBA misreports a syntax error (i.e. the "as string" > qualifier) by ignoring the definition of the function, thereby making the > "=functionName" reference indicate the error indirectly. > > /Al > Quote: > > Claude Lachapelle > > Systems Administrator, MCSE > > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: VBScript to search LDAP from Excel function? Where did you put the function definition ? In a module ? What happens if you wrap the function using a "tester" sub and run it that way ? If there are problem that should show them clearly. Sub Tester() Debug.Print ADUserLookup("AUSERID") End Sub Tim "Claude Lachapelle" <ClaudeLachapelle@xxxxxx> wrote in message news:288FF5C2-4604-46AA-BB9E-D34F7CF8D6FC@xxxxxx Quote: > Hi! > > I have a VBScript that is working fine from cscript.exe, but I soon as I > put > it into an Excel Function, I'm always getting #NAME as result... what's > wrong, do VBScript is limited when run from Excel? > > Here is the Excel function: > > Function ADUserLookup(cUser As String) > > Set adoCommand = CreateObject("ADODB.Command") > Set ADOConnection = CreateObject("ADODB.Connection") > > ADOConnection.Provider = "ADsDSOObject" > ADOConnection.Open "Active Directory Provider" > adoCommand.ActiveConnection = ADOConnection > > strBase = "<LDAP://domain.com>" > strFilter = "(&(objectCategory=person)(objectClass=user)(cn=" & cUser & > "))" > strAttributes = "sAMAccountName" > strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" > > adoCommand.CommandText = strQuery > adoCommand.Properties("Page Size") = 100 > adoCommand.Properties("Timeout") = 30 > adoCommand.Properties("Cache Results") = False > > Set adoRecordset = adoCommand.Execute > > If adoRecordset.EOF Then > ADUserLookup = "False" > Else > ADUserLookup = "True" > End If > > End Function > > I would like to use this function in a column where the fullname will come > from another colunm: =aduserlookup( a2 ) > > What's wrong? > > Thanks. > > Claude Lachapelle > Systems Administrator, MCSE |
My System Specs![]() |
| | #6 (permalink) |
| | Re: VBScript to search LDAP from Excel function? "Claude Lachapelle" <ClaudeLachapelle@xxxxxx> wrote in message news:7DEE7777-10B2-4FE3-BEAB-CCB94F7E1BD2@xxxxxx Quote: > The function below is from Excel, this is why I'm using "as String" in the > Function declaration. BUT this is pure VBScript, error 800A03EE "Expected ')'" with the character count indicating this is expected just before the "as" phrase? Quote: > and from what I'm > understanding, Excel is supporting VBA, not VBScript... document object module. But excel doesn't just *support* VBA; it uses its own flavour of VBA as its macro language. Quote: > Now I have two choices; running an external VBScript which will open the > .xls file and replace what I need (looking if the user is existing in > Active > Directory) Quote: > OR adapt this VBScript to respect VBA rules. /Al Quote: > > Thanks. > > It seem that not all > > "Al Dunbar" wrote: > Quote: >> >> "Claude Lachapelle" <ClaudeLachapelle@xxxxxx> wrote in >> message news:288FF5C2-4604-46AA-BB9E-D34F7CF8D6FC@xxxxxx Quote: >> > Hi! >> > >> > I have a VBScript that is working fine from cscript.exe, but I soon as >> > I >> > put >> > it into an Excel Function, I'm always getting #NAME as result... what's >> > wrong, do VBScript is limited when run from Excel? >> Yes, there are some differences. The lack of the WSCRIPT object being the >> most obvious. >> >> But, that said, your function is not, strictly speaking, completely valid >> vbscript code. vbscript does not support the "as {type}" qualifier. >> Perhaps >> VBA does (that is the macro language of the office components). >> >> So, when you run this from cscript, what does it display for you? >> >> See another comment just past the end of your code. >> Quote: >> > Here is the Excel function: >> > >> > Function ADUserLookup(cUser As String) >> > >> > Set adoCommand = CreateObject("ADODB.Command") >> > Set ADOConnection = CreateObject("ADODB.Connection") >> > >> > ADOConnection.Provider = "ADsDSOObject" >> > ADOConnection.Open "Active Directory Provider" >> > adoCommand.ActiveConnection = ADOConnection >> > >> > strBase = "<LDAP://domain.com>" >> > strFilter = "(&(objectCategory=person)(objectClass=user)(cn=" & cUser & >> > "))" >> > strAttributes = "sAMAccountName" >> > strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" >> > >> > adoCommand.CommandText = strQuery >> > adoCommand.Properties("Page Size") = 100 >> > adoCommand.Properties("Timeout") = 30 >> > adoCommand.Properties("Cache Results") = False >> > >> > Set adoRecordset = adoCommand.Execute >> > >> > If adoRecordset.EOF Then >> > ADUserLookup = "False" >> > Else >> > ADUserLookup = "True" >> > End If >> > >> > End Function >> > >> > I would like to use this function in a column where the fullname will >> > come >> > from another colunm: =aduserlookup( a2 ) >> > >> > What's wrong? >> I'm not completely sure, but it seems odd to me that your ADUserLookup >> routine will return either a value of "True" or "False" rather than some >> useful attribute of the account. Also, depending on the syntax of your >> "full >> name" attribute, it could be that it contains some character special to >> excel. Finally, perhaps VBA misreports a syntax error (i.e. the "as >> string" >> qualifier) by ignoring the definition of the function, thereby making the >> "=functionName" reference indicate the error indirectly. >> >> /Al >> Quote: >> > Claude Lachapelle >> > Systems Administrator, MCSE >> >> |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Vbscript to Search Excel | VB Script | |||
| VBScript function in a .htm page | VB Script | |||
| Search.All in AD (LDAP) found exactly 1000 - is this a built in limit? | PowerShell | |||
| new to excel and vbscript - need help | VB Script | |||
| Wilcard Ldap search | PowerShell | |||