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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Contacts from a spreadsheet

Status
Not open for further replies.

yellowartist

IS-IT--Management
Aug 5, 2007
19
0
0
US
I have about 400 Contact cards I need to create. I am running into an error when creating the mailNickname. I want it to be a phone number however I get the following error.
[highlight]
Line: 40
Char: 4
Error: Unspecified error
Code: 80004005
Source: (null)
[/highlight]

It will work when I do (PhoneNumber@phonecarrier.com).

Here is the Code:
Code:
' ContactExcel .vbs
' Purpose VBScript to create contacts from a list on names in Excel

' --------------------------------------------------------------' 

Option Explicit
Dim objRootLDAP, objContainer, objContact, objExcel, objSheet
Dim strOU, strContactName, strPathExcel, strEmail
Dim intRow, strYourDescription, strFirst, strLast, strAlias, StrDisplay

' Set string variables
' Note: Assume an OU called suppliers exists.
strOU = "domain.com/OU=_ADC ," ' Note the comma
strPathExcel = "z:\Scripts\contacts.xls"
strYourDescription = "Guy's Contact"
intRow = 2 ' Row 1 contains headings

' Section to bind to Active Directory
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://" & strOU & objRootLDAP.Get("DefaultNamingContext")) 

' Open the Excel spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objSheet = objExcel.Workbooks.Open(strPathExcel)

' Here is the loop that cycles through the cells
Do Until (objExcel.Cells(intRow,1).Value) = ""
   strContactName = objExcel.Cells(intRow, 1).Value
   strAlias = objExcel.cells(intRow, 2).Value
   strEmail = objExcel.cells(intRow, 3).Value
   strFirst = objExcel.cells(intRow, 4).Value
   strLast = objExcel.cells(intRow, 5).Value
   StrDisplay  = objExcel.cells(intRow, 6).Value
  
     ' Build the actual contacts.
   Set objContact = objContainer.Create("Contact","cn=" & strContactName)
   objContact.Put "Mail", strEmail
   objContact.Put "givenName", strFirst
   objContact.Put "sn", strLast
   objContact.Put "mailNickname", strAlias
   objContact.Put "proxyAddresses", "SMTP:" & strEmail
   objContact.Put "targetAddress", "smtp:" & strEmail
   objContact.SetInfo

intRow = intRow + 1
Loop

Wscript.Echo "Done"
objExcel.Quit 

WScript.Quit
 
I had a quick look for the error code 80004005 in google, there are a few different errors, but they seem to point to the field you are trying to write to as being unavailable or un-writeable.

Check the values you are attempting to place in this field, make sure that they are suitable.

Also check your active directory schema and make sure the field exists, I've had a look at ours and it doesn't, so I assume it's added by Exchange. You can access the schema by adding the snap in to an MMC.
 
as BillDoor says, try explicitly converting what you have when you try and assign it

objContact.Put "mailNickname", CStr(strAlias)

i presume that mailNickname is a string type
 
The field is added through our exchange piece, adding the Cstr(strAlias) worked.

Thank you very much!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top