Excel Contact Script

Home Forums Scripting General Scripting Excel Contact Script

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    ekrengel
    Member
    #124995

    I have this script that will import the contacts from excel into AD….but when it comes into a blank cell where there is no information for lets say the phone number of that contact, then it errors out. Does anyone know how to skip the part where it “puts” the information into the contact if that value in the cell is blank? Here is my code…

    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
    strFirst = objExcel.cells(intRow, 2).Value
    strMiddle = objExcel.cells(intRow, 3).Value
    strLast = objExcel.cells(intRow, 4).Value
    strDep = objExcel.cells(intRow, 5).Value
    strHomePhone = objExcel.cells(intRow, 6).Value
    strMobilePhone = objExcel.cells(intRow, 7).Value
    strFax = objExcel.cells(intRow, 8).Value
    strCity = objExcel.cells(intRow, 9).Value
    strZip = objExcel.cells(intRow, 10).Value
    strState = objExcel.cells(intRow, 11).Value
    strEmail = objExcel.cells(intRow, 12).Value
    strTitle = objExcel.cells(intRow, 13).Value
    strMemberOf = objExcel.cells(intRow, 14).Value
    strOfficePhone = objExcel.cells(intRow, 15).Value
    strStreet = objExcel.cells(intRow, 16).Value
    strCompany = objExcel.cells(intRow, 17).Value
    strTitle2 = objExcel.cells(intRow, 18).Value
    strStreet2 = objExcel.cells(intRow, 19).Value
    strMailEnable = objExcel.cells(intRow, 20).Value
    strAlias = objExcel.cells(intRow, 21).Value
    strTargetAddress = objExcel.cells(intRow, 22).Value

    Set objContact = objContainer.Create(“Contact”,_
    “cn=” & strContactName)

    objContact.Put “givenName”, strFirst
    objContact.Put “initials”, strMiddle
    objContact.Put “sn”, strLast
    objContact.Put “department”, strDep
    objContact.Put “homePhone”, strHomePhone
    objContact.Put “mobile”, strMobilePhone
    objContact.Put “facsimileTelephoneNumber”, strFax
    objContact.Put “l”, strCity
    objContact.Put “postalCode”, strZip
    objContact.Put “c”, strState
    objContact.Put “mail”, strEmail
    objContact.Put “title”, strTitle
    objContact.Put “memberOf”, strMemberOf
    objContact.Put “telephoneNumber”, strOfficePhone
    objContact.Put “st”, strStreet
    objContact.Put “company”, strCompany
    objContact.Put “description”, strTitle2
    objContact.Put “streetAddress”, strStreet2
    objContact.Put “EnableExchangeMail”, strMailEnable
    objContact.Put “mailNickname”, strAlias
    objContact.Put “targetAddress”, strTargetAddress
    objContact.SetInfo

    intRow = intRow + 1
    Loop
    objExcel.Quit[/CODE][CODE]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
    strFirst = objExcel.cells(intRow, 2).Value
    strMiddle = objExcel.cells(intRow, 3).Value
    strLast = objExcel.cells(intRow, 4).Value
    strDep = objExcel.cells(intRow, 5).Value
    strHomePhone = objExcel.cells(intRow, 6).Value
    strMobilePhone = objExcel.cells(intRow, 7).Value
    strFax = objExcel.cells(intRow, 8).Value
    strCity = objExcel.cells(intRow, 9).Value
    strZip = objExcel.cells(intRow, 10).Value
    strState = objExcel.cells(intRow, 11).Value
    strEmail = objExcel.cells(intRow, 12).Value
    strTitle = objExcel.cells(intRow, 13).Value
    strMemberOf = objExcel.cells(intRow, 14).Value
    strOfficePhone = objExcel.cells(intRow, 15).Value
    strStreet = objExcel.cells(intRow, 16).Value
    strCompany = objExcel.cells(intRow, 17).Value
    strTitle2 = objExcel.cells(intRow, 18).Value
    strStreet2 = objExcel.cells(intRow, 19).Value
    strMailEnable = objExcel.cells(intRow, 20).Value
    strAlias = objExcel.cells(intRow, 21).Value
    strTargetAddress = objExcel.cells(intRow, 22).Value

    Set objContact = objContainer.Create(“Contact”,_
    “cn=” & strContactName)

    objContact.Put “givenName”, strFirst
    objContact.Put “initials”, strMiddle
    objContact.Put “sn”, strLast
    objContact.Put “department”, strDep
    objContact.Put “homePhone”, strHomePhone
    objContact.Put “mobile”, strMobilePhone
    objContact.Put “facsimileTelephoneNumber”, strFax
    objContact.Put “l”, strCity
    objContact.Put “postalCode”, strZip
    objContact.Put “c”, strState
    objContact.Put “mail”, strEmail
    objContact.Put “title”, strTitle
    objContact.Put “memberOf”, strMemberOf
    objContact.Put “telephoneNumber”, strOfficePhone
    objContact.Put “st”, strStreet
    objContact.Put “company”, strCompany
    objContact.Put “description”, strTitle2
    objContact.Put “streetAddress”, strStreet2
    objContact.Put “EnableExchangeMail”, strMailEnable
    objContact.Put “mailNickname”, strAlias
    objContact.Put “targetAddress”, strTargetAddress
    objContact.SetInfo

    intRow = intRow + 1
    Loop
    objExcel.Quit[/CODE]

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.