Solved

Outlook 2010:Remove TelNo's Programmatically

Posted on 2013-06-18
7
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 39257272
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
ID: 39257547
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
ID: 39258872
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:JimPNicholls
ID: 39259154
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
ID: 39259412
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
ID: 39259799
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
ID: 39259873
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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Progress
Suggested Courses

632 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