Advertisement
gn4711

Outlook Format Contact DisplayEmailAdress

Feb 27th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  Dim app As Outlook.Application
  2.     Set app = CreateObject("Outlook.Application")
  3.    
  4.     Dim ns As Outlook.NameSpace
  5.     Set ns = app.GetNamespace("MAPI")
  6.     ns.Logon
  7.    
  8.     Dim contacts As Outlook.MAPIFolder
  9.     Set contacts = ns.GetDefaultFolder(olFolderContacts)
  10.    
  11.     Dim Item As Outlook.ContactItem
  12.     Dim sDisplayAs As String
  13.    
  14.     For Each Item In contacts.Items
  15.    
  16.         sDisplayAs = ""
  17.    
  18.         If (Len(Item.FirstName) * Len(Item.LastName) > 0) Then
  19.             sDisplayAs = Item.LastName + ", " + Item.FirstName
  20.         Else
  21.             sDisplayAs = Item.FileAs
  22.         End If
  23.            
  24.         If Item.CompanyName = "GERMANY" Or Item.CompanyName = "UNITED KINGDOM" Or Item.CompanyName = "NETHERLANDS" Then
  25.             sDisplayAs = sDisplayAs + " (Microsoft)"
  26.             Item.CompanyName = "Microsoft"
  27.         ElseIf Len(Item.CompanyName) > 0 Then
  28.             sDisplayAs = sDisplayAs + " (" + Item.CompanyName + ")"
  29.         End If
  30.        
  31.        
  32.         If (Len(sDisplayAs) > 0) Then
  33.             Item.Email1DisplayName = sDisplayAs
  34.             Item.Save
  35.         End If
  36.      
  37.     Next
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement