none
Outlook 2007 macro, convert contacts to lowercase and remove whitespaces RRS feed

  • Question

  • (An issue has risen, check my next message)

    I want to change the e-mail address of all contacts in Outlook to lowercase and remove whitespaces.


    This is what I have done. Please don't ask why I do both Trim() and Replace()

    Is there any better way of doing this or is there perhaps something I've missed?

    
    Private Sub ReFileContacts()
     Dim items As items, item As ContactItem, folder As folder
     Dim contactItems As Outlook.items
     Dim itemContact As Outlook.ContactItem
     
     Set folder = Session.GetDefaultFolder(olFolderContacts)
     Set items = folder.items
     Count = items.Count
     If Count = 0 Then
     MsgBox "Nothing to do!"
     Exit Sub
     End If
     
     'Filter on the message class to obtain only contact items in the folder
     Set contactItems = items.Restrict("[MessageClass]='IPM.Contact'")
     
     For Each itemContact In contactItems 'Loop through all contacts
        itemContact.Email1Address = LCase(itemContact.Email1Address) 'Lowercase
        itemContact.Email1Address = Trim(itemContact.Email1Address) 'Trim trailing and leading spaces
        itemContact.Email1Address = Replace(itemContact.Email1Address, " ", "") 'Trim any remaining spaces
        itemContact.Save 'Save the contact
     Next
     
     MsgBox "Your contacts have been converted to lowercase without whitespaces."
    End Sub

    Thank you!


    Monday, September 10, 2012 11:44 AM

All replies

  • You could replace the three lines with

    itemContact.Email1Address = Replace(LCase(itemContact.Email1Address), " ", "")

    What about the other e-mail addresses that may be associated with the contact?


    Graham Mayor - Word MVP
    www.gmayor.com

    Monday, September 10, 2012 1:52 PM
  • You could replace the three lines with

    itemContact.Email1Address = Replace(LCase(itemContact.Email1Address), " ", "")

    What about the other e-mail addresses that may be associated with the contact?


    Graham Mayor - Word MVP
    www.gmayor.com


    Hello, thank you that's a good tip ;)

    These contacts use a custom form (changed the IPM.Contact to IPM.Contact.112607)

    When I run this (Contact folder has 20.000 contacts) I get the following error:


    runtime error -1836974071 (92820009)

    one or more items in the folder you synchronized do not match.
    to resolve the conflicts, open the items and try the operation again

    I really have no idea where to go from here...



    Monday, September 10, 2012 5:06 PM
  • I regret I don't know much about custom forms, but the implication or the error seems to be that the field on your custom form is called something other than Email1Address

    Graham Mayor - Word MVP
    www.gmayor.com

    Tuesday, September 11, 2012 5:28 AM
  • Hmm, that can't be it, because if I do Msgbox(itemContact.Email1Address) it gives me the e-mail address of each contact.

    Tuesday, September 11, 2012 9:48 AM