VBScript: Clean Up Imported SIM Card Contacts in Outlook

Filed under: VBScript — Written by Chrissy on Friday, April 11th, 2008 @ 2:11 pm

The other day, I was texting a friend and some guy looked at me and said "Oh hey, 2002 called, it wants its T9 back." Haha, slightly cliche but I laughed anyway. Then I went and bought myself a Blackberry.

I totally love it, I won't lie. So I imported my contacts into Outlook from a Sony Ericsson mobile phone and they came out kinda chu-chu. All the contacts came in as "Work" numbers and were all prefixed by ";\M". I cleaned the M's out manually but then wrote a script to list all the numbers as Mobile numbers. For consistency's sake, I also cleaned up all of the numbers themselves to just be, for instance, 2345551212. Here's the script in case you would like to do a mass cleanse as well.

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
 
Set colContacts = objNamespace.GetDefaultFolder(10).Items ' 10 = olFolderContacts
 
For Each objContact In colContacts
  if len(objContact.MobileTelephoneNumber) = 0 then
    objContact.MobileTelephoneNumber = objContact.BusinessTelephoneNumber
    objContact.BusinessTelephoneNumber = ""
    'Wscript.Echo objContact.FullName, objContact.BusinessTelephoneNumber, objContact.MobileTelephoneNumber
    objContact.Save
  end if
  
  if len(objContact.MobileTelephoneNumber) > 0 then
    mobileNumber = objContact.MobileTelephoneNumber
    mobileNumber = replace(mobileNumber," ","")
    mobileNumber = replace(mobileNumber,"-","")
    mobileNumber = replace(mobileNumber,"(","")
    mobileNumber = replace(mobileNumber,")","")
    mobileNumber = replace(mobileNumber,"+1","")
    
    if left(mobileNumber,1) = "1" then mobileNumber = right(mobileNumber,len(mobileNumber)-1)
    objContact.MobileTelephoneNumber = mobileNumber
    objContact.Save
  End if
  
Next

Ouu my grammar has gone downhill since I spent a weekend in Louisiana.