Conditionally deleting contacts

J

John

Hi

Could someone please show me how to, programmatically, go through a contacts
folder called clients and clear all contacts except those that have category
personal? I have written some code (given below) but don't know how to check
for the category field of a contact item and then delete the item if it does
not have personal in the category.

Thanks

Regards

O = New Outlook.Application
F =
O.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts).Folder
s().Item("Clients")

ICount = F.Items.Count
For I = 1 To ICount
if not {check for category field of the Ith item for 'personal'} then
{Delete Ith contact item}
end if
Next I
 
K

Ken Slovak - [MVP - Outlook]

Always delete items using a down counting loop, otherwise the loop counter
gets itself confused and the indexes of the items in the collection change
for every item you delete.

Dim oContact As Outlook.ContactItem

ICount = F.Items.Count
For I = ICount To 1 Step -1
Set oContact = F.Items(I)
If Not (InStr(1, oContact.Categories, "Personal") > 0) Then
oContact.Delete
End If
Next I
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top