Changing Contact Phone

  • Thread starter Thread starter Guy
  • Start date Start date
G

Guy

I am trying to write a script that will change the
contacts phone numbers. I am able to display the phone
number but when i try to set a new value to the
businessphonenuber property it does not change.
 
Are you Saving the contact afterward?

Try it like this:
'----------------------------------------------------

' Put code to create & set Outlook.Application object,
' namespace object, etc. here

Dim itmItems As Items
Dim itmContact As Object

For Each itmContact In itmItems
With itmContact
' make sure item is a contact:
If .Class = olContact Then
' put your code to change the phone # here
.Save
End If
End With

' Don't forget to set all object references = Nothing
'----------------------------------------------------

That should do it.

-Andrew
=======================================================
 
I used the following code:

Sub ChangeNumber()
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = _
myNameSpace.GetDefaultFolder(olFolderContacts)
Set itmContact = myFolder.Items
Dim I As Integer

For I = 37 To itmContact.Count
If Left(itmContact(I).BusinessTelephoneNumber, 4)
= "+972" Then
bphone = itmContact(I).BusinessTelephoneNumber
itmContact(I).BusinessTelephoneNumber = "0" + Mid
(bphone, 7, 1) + "-" + Mid(bphone, 10, 10)
itmContact(I).Save
End If
Next
End Sub

At some point when i stepped through the code, it worked.
But when i try to run the macro it does not work. I don't
know exactly what i did that made it work when i stepped
through it.
 
Back
Top