Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can not handle numbers from excel 1

Status
Not open for further replies.

wibbe

IS-IT--Management
Oct 30, 2002
68
0
0
SE
Hi,

I have a problem and can not find the error.
This is a modefied script from Microsoft to create a user in Active Directory. I have just added some code to get the information from a excel document.
It worksfine if a add text or mixed content, but if I try to add just numbers it will return error -2147467259.

Ex.
postalCode = 100 00 (workes fine)
postalCode = 10000 (does not work)


Code:
--------------------------------------------------------
On error resume next
Dim arrADAtt(2,50)
Randomize
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open ("[file.xls]")

wscript.echo "1: " & err
'Set domain information
Set objOU = GetObject("LDAP://[OU DN])

wscript.echo "2: " & err
'Get all attributes from the first line.
intCol = 1
arr = 0
Do Until objExcel.Cells(1, intCol).Value = ""
Select Case objExcel.Cells(1, intCol).Value
Case "Result" strResultCol = intCol
Case "MailboxStore" strMailboxStoreCol = intCol
Case "Password" strPasswordCol = intCol
Case "cn" strcnCol = intCol
Case Else
arrADAtt(1,arr) = objExcel.Cells(1, intCol).Value
arrADAtt(2,arr) = intCol
arr = arr + 1
End Select
intCol = intCol + 1
Loop
wscript.echo "3: " & err
' Validate the gatherd attributes
If strResultCol = "" then Msgbox "Add a 'Result' column and try again" : funquit
If strPasswordCol = "" then Msgbox "Add a 'Password' column and try again" : funquit
If strcnCol = "" then Msgbox "Add a 'cn' column and try again" : funquit
If strMailboxStoreCol = "" then
answer = Msgbox("No mailboxstore is pressent in the datafile." & chr(13) & "No mailbox will be created. " & chr(13) & "Do you want to continue anyway?",305,"Warning")
If answer = 2 Then
funquit
End If
End If
wscript.echo "4: " & err
'Create user
intRow = 2

Do Until objExcel.Cells(intRow,1).Value = ""
Set Usr = objOU.Create("User","CN=" & UCase(objExcel.Cells(intRow,strcnCol).Value))
wscript.echo "5: " & err
arr = 0
Do Until arrADAtt(1,arr) = ""
usr.put arrADAtt(1,arr), objExcel.Cells(intRow,arrADAtt(2,arr)).Value
wscript.echo arrADAtt(1,arr) & " " & objExcel.Cells(intRow,arrADAtt(2,arr)).Value
arr = arr + 1
Loop

usr.setinfo
wscript.echo "6: " & err
strPW = "Scania." & int(1000 * Rnd())
objExcel.Cells(intRow,strPasswordCol).Value = strPW
usr.setpassword strPW
usr.setinfo
wscript.echo "7: " & err
If not strMailboxStoreCol = "" Then
'Create Mailbox
usr.CreateMailbox "Ldap://" & objExcel.Cells(intRow,strMailboxStoreCol).Value
usr.setinfo
wscript.echo "8: " & err
End If

' Done with this user, now we check status.
If err = 0 Then
objExcel.Cells(intRow,strResultCol).Value = "Done"
else
objExcel.Cells(intRow,strResultCol).Value = err
err = 0
End If

intRow = intRow + 1
Loop

objExcel.Save
objExcel.Quit

Function funquit
objExcel.Quit
wscript.Quit
End Function
----------------------------------------------------------
 
try and explicitly convert you variable to whatever the property is you are trying to update...

so, in this case is AD expecting a string? in which case use

CStr(objExcel.Cells(intRow,arrADAtt(2,arr)).Value)

but i think what you are trying to achieve will need more work, you are updating attributes dynamically using Put which is cool but you need to consider the above as well...i.e. make sure the type of variable you are passing is the correct one...perhaps in the (1,arr) cell you need to do something like

%attribute%_int
%attribute%_str

and then in your code do CInt() CStr() based on splitting the 1,arr strings??? or perhaps i am over complicating things
 
Thanks mrmovie. That worked fine.

And yes, you are right, I have to figure out how to handle diffrent data types.

I try to recreate the "header.exe"-tool included for Exchange 5.5, but now for Active Directory.

I have a script that let you choose the objects to import/export depending on the current scheema in AD.
I guess I have to extract the datatype from AD as well.

Thanks again!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top