
Trying to set the way contacts are stored via FileAs
Trying to set the way contacts are stored via FileAs.
Here is my code - it is a quick Macro I wrote, but it does not update the
contact?
I am using Outlook 2000.
Thanks for any help. Chris
Public Sub CorrectContacts()
Dim ofContacts As MAPIFolder
Dim oicItems As Items
Dim ocContact As ContactItem
Dim i As Integer
Dim sFirstName As String
Dim sLastName As String
Dim sCompanyName As String
Set ofContacts =
Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)
Set oicItems = ofContacts.Items
'Set ocContact = oicItems.Item(1)
Open "C:\CorrectContacts.txt" For Output As #1
Print #1, "***********************************************"
For i = 1 To ofContacts.Items.Count
If Left(oicItems.Item(i), 1) = "*" Then
Print #1, "Skip Item: " & oicItems.Item(i)
Debug.Print "Skip Item: " & oicItems.Item(i)
Else
sFirstName = Trim(oicItems.Item(i).FirstName)
sLastName = Trim(oicItems.Item(i).LastName)
' Debug.Print "*********************************"
If sFirstName = "" And sLastName = "" Then
' use company name
sCompanyName = Trim(oicItems.Item(i).CompanyName)
If sCompanyName = "" Then
' skip - not sure what to do
' Debug.Print "Skip Item (because no first, last, or company
name found): " & oicItems.Item(i)
Else
' use the company name - in the FileAs
Print #1, "File Contact As: " & sCompanyName
oicItems.Item(i).FileAs = sCompanyName
End If
Else
If sLastName = "" Then
' use first name
Print #1, "File Contact As: " & sFirstName
oicItems.Item(i).FileAs = sFirstName
Else
If sFirstName = "" Then
' only store the last name
Print #1, "File Contact As: " & sLastName
oicItems.Item(i).FileAs = sLastName
Else
' store both the last name and first name
sFirstName = sLastName & ", " & sFirstName
Print #1, "File Contact As: " & sFirstName
'oicItems.Item(i).UserProperties("[FileAs]") =
sFirstName
oicItems.Item(i).FileAs = sFirstName
'oicItems.Item(i).FileAs = sFirstName & ", " & sLastName
End If
End If
End If
oicItems.Item(i).Save
End If
Next i
Print #1, "***********************************************"
Close #1
Set ofContacts = Nothing
Set oicItems = Nothing
MsgBox "Finished -- For a report open file: C:\CorrectContacts.txt"
End Sub