Change Phone Number Format 
Author Message
 Change Phone Number Format

Hi Chris.

I have a similar problem but it is that Fusion 1 sync software hands me
totally unformatted lits of digits as phone numbers.

The code here works fine for the conversion. To get it to do what you want
it to do just modofy the "Parsephone" function to test for the types of
numbers you want to convert and do the conversion. All of this utilizes
fairly strait-forward string handling techniques.

Good luck,


Public Sub FormatPhone()

'Reformat phone numbers in (nnn) nnn-nnnn format. This is useful to clean up
phone numbers
'imported from Sprint using Fusion One sync software

    Dim myOlApp As Outlook.Application, myNameSpace As NameSpace, myFolder
As MAPIFolder
    Dim myItem As ContactItem, myItems As Items

    'Initialize Control Blocks
    Set myOlApp = New Outlook.Application
    Set myNameSpace = myOlApp.GetNamespace("MAPI")
    Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
    Set myItems = myFolder.Items

    'Cycle thru all contacts in default contact folder

    For Each myItem In myItems

        'Make sure this is a contact item

        If myItem.Class = olContact Then

            ' Update phone number fields of interest

            myItem.HomeTelephoneNumber =
            myItem.BusinessTelephoneNumber =
            myItem.MobileTelephoneNumber =
            myItem.OtherTelephoneNumber =
            myItem.Close (olSave)

        End If

    Next myItem

    Set myItem = Nothing
    Set myItems = Nothing
    Set myFolder = Nothing
    Set myNameSpace = Nothing
    Set myOlApp = Nothing

End Sub

Private Function ParsePhone(ByVal Phone As String) As String

' Convert phone number from nnnnnnnnnn to (nnn) nnn-nnnn

    Dim i As Integer

    ' Set return for early exit

    ParsePhone = Phone

    ' Make sure length is exactly 10 digits and it consists only of the
digits 0-9

    If Len(Trim(Phone)) <> 10 Then Exit Function
    For i = 1 To 10
        If (Mid(Phone, i, 1) < "0") Or (Mid(Phone, i, 1) > "9") Then Exit
    Next i

    ' Reformat number and return

    ParsePhone = "(" & Left(Phone, 3) & ")" & " " & Mid(Phone, 4, 3) & "-" &
Right(Phone, 4)

End Function

> Hi!

> Call me unusual, but I've a penchant to change all my
> Contact phone numbers' formats from "(nnn) nnn-
> nnnn", "nnn/nnn-nnnn" and others to "nnn.nnn.nnnn".  I
> think using a decimal provides the best readability.

> Anyway, I can't find any code to do this, and I am too
> much of a newbie to write it from scratch myself.  Anyone
> got some code to share?

> Chris

Fri, 04 Mar 2005 18:26:41 GMT  
 [ 1 post ] 

 Relevant Pages 

1. microsoft outlook phone number formatting

2. Format phone number inside textbox control

3. format a phone number

4. formatting phone number

5. Formatting Phone Numbers

6. Format Phone Number

7. Format Phone number read from access database

8. phone number formatting

9. Formatting a Text Box for phone numbers

10. phone number format

11. Format Phone Number

12. format phone numbers


Powered by phpBB® Forum Software