trying to delete outlook contact (1 Viewer)

Andy Mc

New member
Local time
Today, 02:55
Joined
May 6, 2012
Messages
13
Hi
I'm trying to use this code that I found online:

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
If myItems.Email1Address = "j@yoursite.com" Then 'I'm substituting my own address here
myItems.Delete
End If
Next

It keeps getting stuck at the For line (error: Type mismatch). It's got to be something simple, but I simply can't see what the problem is, can anyone enlighten me?
PS: I'm not a programmer, just a keen amateur
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:55
Joined
Oct 29, 2018
Messages
13,739
Hi Andy. I might try it with a couple of changes. For example:

Dim myContacts As Object
Dim myItems As Variant

Set myContacts = myInformation.GetDefaultFolder(olFolderContacts)

For Each myItems In myContacts.Items
...

(untested)
Hope that helps...
 

Andy Mc

New member
Local time
Today, 02:55
Joined
May 6, 2012
Messages
13
Thanks for teh swift reply.

Tried this but get a fail at the if statement (property doesn't support this property or method). Any suggestions?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:55
Joined
Oct 29, 2018
Messages
13,739
Thanks for teh swift reply.

Tried this but get a fail at the if statement (property doesn't support this property or method). Any suggestions?
Try adding this line:

Rich (BB code):
For Each...
    If myItems.Class = olContact Then
        If myItems.Email1Address...
Hope that helps...
 

Users who are viewing this thread

Top Bottom