VBScript: Clean Up Imported SIM Card Contacts in Outlook

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.

Chrissy is a PowerShell MVP who has worked in IT for nearly 20 years, and currently serves as a Sr. Database Engineer in Belgium. Always an avid scripter, she attended the Monad session at Microsoft’s Professional Developers Conference in Los Angeles back in 2005 and has worked and played with PowerShell ever since. Chrissy is currently pursuing an MS in Systems Engineering at Regis University and helps maintain RealCajunRecipes.com in her spare time. She holds a number of certifications, including those relating to SQL Server, SuSE Linux, SharePoint and network security. She recently became co-lead of the SQL PASS PowerShell Virtual Chapter. You can follow her on Twitter at @cl.

Posted in VBScript
4 comments on “VBScript: Clean Up Imported SIM Card Contacts in Outlook
  1. bryan says:

    thank you!!

  2. Omer says:

    Thanks for this helpful code :)

    Omer KARADENIZ
    http://www.omerkaradeniz.com

  3. Pretty cool script.

    “if left(mobileNumber,1) = “1” then mobileNumber = right(mobileNumber,len(mobileNumber)-1)”

    Using mid(mobileNumber,2) would be cleaner. That’s nit-picking though.
    sorry. ;-)

    I like your website by the way. I’m book-marking it right now.

  4. Chrissy says:

    Very true! I totally forgot about mid(). Thanks Patrick.

Leave a Reply

Your email address will not be published. Required fields are marked *

*