I am using 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 = 1 To itmContact.Count
If Left(itmContact(I).BusinessTelephoneNumber, 4)
= "+972" Then
bphone = itmContact(I).BusinessTelephoneNumber
itmContact(I).BusinessTelephoneNumber.erase
itmContact(I).BusinessTelephoneNumber = "0" + Mid
(bphone, 7, 1) + "-" + Mid(bphone, 10, 10)
itmContact(I).Save
End If
Next
End Sub
It is not changing the telephone number. At some point
when i was stepping through the code, it worked, but when
i ran the macro it did not work. I do not know what i did
to make it work.
Andrew Cushen - 28 May 2004 16:08 GMT
Did you read my answer to your earlier post? I don't see
where you're checking if itmContact(I) is actually a
COntact item. Remember, you can have different types of
items in your COntacts folder, like Distribution Lists.
Just because an item is in your Contacts folder, doesn't
make it a Contact item.
Try this If Test before you test for the 972 area code:
>-----Original Message-----
>I am using the following code:
[quoted text clipped - 23 lines]
>to make it work.
>.
Guy Perry - 28 May 2004 16:37 GMT
Yes, i read it, thank you. I added the Save as you recommended but it
did not help.
I now also added the line you suggested, and it is a Contact item, but
still it did not work.
When i am debugging the code it seems all to work fine. It meets the IF
criteria and the variable gets the correct value. The problem occurs
when it tries to assign the value to the
itmContact(I).BusinessTelephoneNumber = NewNumber. It simply does not
change the value.
Any other suggestions?
Andrew Cushen - 28 May 2004 16:13 GMT
Sorry, accidentally posted my last before I finished.
Try this:
If itmContact(I).Class = olContact Then
'Pick up your code:
If Left(itmContact(I).BusinessTelephoneNumber, 4) _
"+972" Then
'etc.
Not sure if that will fix your problem, but it needs to be
done either way. You'll either get an error, or your code
just won't work, if you try to process an item that isn't
a Contact Item.
HTH,
-Andrew
=====================================
>-----Original Message-----
>I am using the following code:
[quoted text clipped - 23 lines]
>to make it work.
>.