Outlook Contacts Macro
A while back I decided I was fed up of having to keep adjustings my Outlook contacts to show in the form 'Firstname Lastname' instead of the default 'Lastname, Firstname' which my phone seems to add new contacts as, so I looked into writing a macro to do the job for me.
At first my search was confusing and fruitless, but eventually I stumbled across someone's site, which had a VB script that did something similar. Unfortunately, I don't remember which site, so sorry for not acknowledging it!
I used the following code as a macro within Outlook to edit all of my contacts into the format 'Firstname Lastname'.
This I have filed under a macro called ThisOutlookSession.ChangeFileAs.
Public Sub ChangeFileAs()
Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objContact As Outlook.ContactItem
Dim objItems As Outlook.Items
Dim objContactsFolder As Outlook.MAPIFolder
Dim obj As Object
Dim strFirstName As String
Dim strLastName As String
Dim strFileAs As String
On Error Resume Next
Set objOL = CreateObject("Outlook.Application")
Set objNS = objOL.GetNamespace("MAPI")
Set objContactsFolder = objNS.GetDefaultFolder(olFolderContacts)
Set objItems = objContactsFolder.Items
For Each obj In objItems
'Test for contact and not distribution list
If obj.Class = olContact Then
Set objContact = obj
With objContact
strFirstName = .FirstName
strLastName = .LastName
strFileAs = strFirstName & " " & strLastName
.FileAs = strFileAs
.Save
End With
End If
Err.Clear
Next
Set objOL = Nothing
Set objNS = Nothing
Set obj = Nothing
Set objContact = Nothing
Set objItems = Nothing
Set objContactsFolder = Nothing
End Sub
Again - apologies for not acknowledging the source of the main body of this code!
Hope this helps someone (or me) in the future!
Comments
- It helped me. I wanted to copy all the first names of my contacts into the nickname field, so then I could easily modify just those that went by another name or a diminutive. One little tweak to this script did the trick. Thanks for your help! - Blake on Fri Aug 25 2006 14:08:17 GMT+0000 (Coordinated Universal Time)