Solved

Outlook 2010:Remove TelNo's Programmatically

Posted on 2013-06-18
7
221 Views
Last Modified: 2014-06-27
Outlook 2010 Exchange 2010

I have an issue where personal mobiles were added to Outlook contacts during a recent Lync 2010 rollout (The personal numbers were in the IPPhone field in AD which should have been hidden from the users but when adding a LYNC contact, pulled this info into Outlook).

Long story short, I need a script which binds all contact numbers together and then delete the offending numbers but not the contact. I haven't a clue where to start so any pointers would be much appreciated.
0
Comment
Question by:JimPNicholls
  • 4
  • 3
7 Comments
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Hi, JimPNicholls.

I can provide a script that will delete the numbers from Outlook contacts, but to do that I need to know which contact field the numbers are in.
0
 

Author Comment

by:JimPNicholls
Comment Utility
Hi BlueDevilFan,

The field this has mapped into is objContact.MobileTelephoneNumber. I have approx 300 possible numbers so I'm just looking for a efficient way to remove them in one hit.

Regards.
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
The script below will delete the value of the MobileTelephoneNumber property on ALL contacts in your default contacts folder.  Please note that the script will delete all mobile numbers including those that did not come from the Lync rollout.

To use it

1.  Open Notepad
2.  Copy the code and paste it into Notepad
3.  Save the file.  You can name it anything you want, but the file extension must be .vbs
4.  Double-click the file to run the script

If anyone else needs to run the script also, then you can place it on a file share they have access to and send them a link pointing to the script.

Const olFolderContacts = 10
Const olContact = 40
Dim olkApp, olkSes, olkFld, olkCon
Set olkApp = CreateObject("Outlook.Application")
Set olkSes = olkApp.GetNamespace("MAPI")
olkSes.Logon olkApp.DefaultProfileName
Set olkFld = olkSes.GetDefaultFolder(olFolderContacts)
For Each olkCon In olkFld.Items
    If olkCon.Class = olContact Then
        olkCon.MobileTelephoneNumber = ""
        olkCon.Save
    End If
Next
olkSes.Logoff
Set olkCon = Nothing
Set olkFld = Nothing
Set olkSes = Nothing
Set olkApp = Nothing
MsgBox "The mobile number on all contacts has been deleted.", vbInformation + vbOKOnly, "Delete Mobile Numbers"

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:JimPNicholls
Comment Utility
Thanks for this. This could work but I don't want to delete all mobile numbers. If I have a txt file listing all numbers, is it possible to effectively loop through each number per contact and if it matches, delete it?
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Yes, that's possible.  Is it one number per line in the text file?  Are the numbers in the text file formatted the same way as they are in Outlook (e.g. (xxx) yyy-zzz)?
0
 

Author Comment

by:JimPNicholls
Comment Utility
If dabbled and come up with the following. I think this'll work and thanks everso for pointing me in the right direction.

Const olFolderContacts = 10
Const olContact = 40
Const ForReading = 1

Dim olkApp, olkSes, olkFld, olkCon
Dim arrFileLines()

Set olkApp = CreateObject("Outlook.Application")
Set olkSes = olkApp.GetNamespace("MAPI")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Users\IPPhone Numbers.txt", ForReading)

'Open the txt file and bind numbers
i = 0
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close

olkSes.Logon olkApp.DefaultProfileName
Set olkFld = olkSes.GetDefaultFolder(olFolderContacts)
For Each olkCon In olkFld.Items
    If olkCon.Class = olContact Then
          For Each strLine in arrFileLines
                  If olkCon.MobileTelephoneNumber = strLine Then
              'olkCon.MobileTelephoneNumber = ""
              'olkCon.Save
              WScript.Echo "Match"
              End If
                  WScript.Echo strLine & " " & olkCon.MobileTelephoneNumber

            Next
End If


Next
olkSes.Logoff
Set olkCon = Nothing
Set olkFld = Nothing
Set olkSes = Nothing
Set olkApp = Nothing
MsgBox "The mobile number on all contacts has been deleted.", vbInformation + vbOKOnly, "Delete Mobile Numbers"
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
Comment Utility
You're welcome.  

I had a slightly different, perhaps faster, solution in mind, but it looks like this will work so long as the numbers in the file are formatted the same way the numbers in Outlook are.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now