Solved

Outlook 2010:Remove TelNo's Programmatically

Posted on 2013-06-18
7
229 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
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vba code required for to attach all .gif (pictures) from folder to email body 4 40
Office 2016 Add-ins GPO 3 41
outlook error send and receive 15 96
Fraud Email 22 78
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

749 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