Changing Contact Phone Number

G

Guy

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.
 
A

Andrew Cushen

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:
 
A

Andrew Cushen

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
=====================================
 
G

Guy Perry

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?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top