nolan
06-09-2011, 01:46 PM
Hi there,
I'm new to writing VBA in outlook, and am consequently not familiar at all with the object model.
I'm trying to write a routine to
1. Delete all contacts in the default contacts folder where the companyName property = X
2. Copy all contacts from the address book to the default contacts folder where the company name of that contact = x
I have an idea how to to delete existing contacts:
Sub DisplayContact()
Dim myOutlook As Outlook.Application
Dim myInformation As NameSpace
Dim myContacts As Items
Dim myItems As ContactItem
Set myOutlook = CreateObject("Outlook.Application")
Set myInformation = myOutlook.GetNamespace("MAPI")
Set myContacts = myInformation.GetDefaultFolder(olFolderContacts).Items
For Each myItems In myContacts
MsgBox (myItems.FirstName)
If myItems.CompanyName = "My Company" Then
myItems.Delete
End If
Next
End Sub
but I'm totally stumped as to how I might selectively import contacts from the address book though VBA.
Any help would be greatly appreciated!
Nolan
I'm new to writing VBA in outlook, and am consequently not familiar at all with the object model.
I'm trying to write a routine to
1. Delete all contacts in the default contacts folder where the companyName property = X
2. Copy all contacts from the address book to the default contacts folder where the company name of that contact = x
I have an idea how to to delete existing contacts:
Sub DisplayContact()
Dim myOutlook As Outlook.Application
Dim myInformation As NameSpace
Dim myContacts As Items
Dim myItems As ContactItem
Set myOutlook = CreateObject("Outlook.Application")
Set myInformation = myOutlook.GetNamespace("MAPI")
Set myContacts = myInformation.GetDefaultFolder(olFolderContacts).Items
For Each myItems In myContacts
MsgBox (myItems.FirstName)
If myItems.CompanyName = "My Company" Then
myItems.Delete
End If
Next
End Sub
but I'm totally stumped as to how I might selectively import contacts from the address book though VBA.
Any help would be greatly appreciated!
Nolan