I need a macro to change my Outlook contacts phone numbers in a way that
the first number excecpt the "021" area code, will be repeated. eg if it is
"0218976456" to "02188976456". It's because of new local telephone company
policies for phone numbers and I know nothing of VBA syntaxes. I would be
really grateful if s.b could help me here on how to create such thing.
Simple, eh? The code below do what you want; it assumes the telephone numbers
are formatted "(021) 8x".
Sub PhoneChange()
Dim itmItem As Object
Dim itmItems As Outlook.Items
Dim objProp As Outlook.ItemProperty
Dim blnChanged As Boolean
Dim lngTotal As Long
Dim lngChanged As Long
Set itmItems = ActiveExplorer.CurrentFolder.Items
lngTotal = itmItems.Count
For Each itmItem In itmItems
blnChanged = False
For Each objProp In itmItem.ItemProperties
If InStr(LCase(objProp.Name), "telephone") <> 0 Then
GoSub Phone88
End If
Next objProp
If blnChanged Then
itmItem.Save
lngChanged = lngChanged + 1
End If
Next itmItem
MsgBox "Total items: " & lngTotal & vbCr & "Changed: " & lngChanged, vbInformation + vbOKOnly, "PhoneChange"
Exit Sub
Phone88:
Call Phone88(objProp.Value, itmItem.ItemProperties.Item(objProp.Name), blnChanged)
Return
End Sub
Private Sub Phone88(strIn As String, objOut As ItemProperty, blnChanged As Boolean)
' Changes "(021) 8xxxxxx" to "(021) 88xxxxxx"
Dim lngPos As Long
' Empty or already in "88" scheme?
If strIn = "" Or InStr(strIn, "(021) 88") <> 0 Then
objOut.Value = strIn
blnChanged = blnChanged Or False
Else
lngPos = InStr(strIn, "(021) 8")
If lngPos <> 0 Then
objOut.Value = Left(strIn, lngPos + 6) & "8" & Mid(strIn, lngPos + 7)
blnChanged = True
Debug.Print "Changed " & strIn & " to " & objOut.Value
Else
objOut.Value = strIn
blnChanged = blnChanged Or False
End If
End If
End Sub