Hi,
I found some VBA code on another forum and adapted it so that I could update my phone numbers with international dialling codes if they didn't already have them. Here's the code:
It would be a good idea to BACK UP contacts before using this!
Sub correct_phone_nos_country_code()
Dim olApp As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim objItems As Outlook.Items
Dim objItem As Object, objAdd As Object
Dim new_no As String
'Loop through all the contacts in the contacts folder, and see if we
' have a match with the LastName and FirstName in the current line,
' and if so, update that contact's data
' TODO: Find out if there's some way to find a matching LastName and FirstName
' in Outlook VBA without having to loop through everything, like maybe an
' equivalent for the FindFirst method in Access VBA?
Set olApp = CreateObject("Outlook.Application")
Set myNameSpace = olApp.GetNamespace("MAPI")
Set objFolder = myNameSpace.GetDefaultFolder(olFolderContacts) ' <-- Main (default) contacts folder
' objFolder.ShowAsOutlookAB = True ' ticks box to see folder content items as contacts
Set objItems = objFolder.Items
For Each objItem In objItems
' Make sure we have a contact item
With objItem
If .Class = olContact Then
Debug.Print .FileAs, .BusinessTelephoneNumber, .HomeTelephoneNumber, .MobileTelephoneNumber
.HomeTelephoneNumber = correct_phone_no_to_international(.HomeTelephoneNumber)
.BusinessTelephoneNumber = correct_phone_no_to_international(.BusinessTelephoneNumber)
.HomeTelephoneNumber = correct_phone_no_to_international(.HomeTelephoneNumber)
.MobileTelephoneNumber = correct_phone_no_to_international(.MobileTelephoneNumber)
.BusinessFaxNumber = correct_phone_no_to_international(.BusinessFaxNumber)
'objItem.BusinessTelephoneNumber = strBusPhone$
'objItem.MobileTelephoneNumber = strMobilePhone$
'objItem.Email1Address = strEmail1$
objItem.Save
End If
End With
Next
End Sub
Function correct_phone_no_to_international(phone_no As String) As String
Dim new_phone_no As String
Dim my_country_code As String
'****change this to your country code:
my_country_code = "+44"
'***********
If Len(Trim(phone_no)) = 0 Then
change_phone_no_to_international = ""
Exit Function
End If
If Left$(phone_no, 1) <> "+" Then
new_phone_no = my_country_code + Mid$(phone_no, 2)
correct_phone_no_to_international = new_phone_no
End If
End Function