PC Review


Reply
Thread Tools Rate Thread

Delete an outlook contact using an Excel macro

 
 
Mathew
Guest
Posts: n/a
 
      2nd Apr 2008
I have an excel spreadsheet that we keep our contacts in. Occasionally, we
need to replace one. When this happens, we just run a macro and it creates
the new contact in Outlook. Thanks to Gram Mayors template on this. But,
now we must go to Outlook and delete the old one. Not a problem for most
people, however, most of my co-workers are soon to be "Darwin Award Winners."
So, I've been tasked with developing a macro that will also delete the old
contact and create the new contact. As I said, I've got the code for the new
contact, but any ideas on how to delete a contact from Excel would be
welcomed. Thanks in advance for any help!
 
Reply With Quote
 
 
 
 
Bernie Deitrick
Guest
Posts: n/a
 
      2nd Apr 2008
Sub TryNow()
Dim objOL As Object
Dim myNS As Outlook.Namespace
Dim ConName As String

ConName = "Mathew"

Set objOL = CreateObject("outlook.application")
Set myNS = objOL.GetNamespace("MAPI")

If myNS.AddressLists("Contacts").AddressEntries(ConName).Name = ConName Then
myNS.AddressLists("Contacts").AddressEntries(ConName).Delete
End If

Set myNS = Nothing
Set objOL = Nothing

End Sub

If a contact name doesn't exist, then the next one is returned - hence the check...

HTH,
Bernie
MS Excel MVP


"Mathew" <(E-Mail Removed)> wrote in message
news:C60F2B29-0CDB-45E1-A3D4-(E-Mail Removed)...
>I have an excel spreadsheet that we keep our contacts in. Occasionally, we
> need to replace one. When this happens, we just run a macro and it creates
> the new contact in Outlook. Thanks to Gram Mayors template on this. But,
> now we must go to Outlook and delete the old one. Not a problem for most
> people, however, most of my co-workers are soon to be "Darwin Award Winners."
> So, I've been tasked with developing a macro that will also delete the old
> contact and create the new contact. As I said, I've got the code for the new
> contact, but any ideas on how to delete a contact from Excel would be
> welcomed. Thanks in advance for any help!



 
Reply With Quote
 
Mathew
Guest
Posts: n/a
 
      15th Apr 2008
Bernie: Thanks for the help. However, the code did not function. I get a
funny error: Run-Time Error -2147221233 (8004010f)': when the code reaches
this line:
If myNS.AddressLists("Contacts").AddressEntries(ConName).Name = ConName Then
Another wrinkle is that I get a message saying that another program is
trying to access Outlook and ask permission to allow this. I check Ok and
the program still fails. Any ideas??


"Bernie Deitrick" wrote:

> Sub TryNow()
> Dim objOL As Object
> Dim myNS As Outlook.Namespace
> Dim ConName As String
>
> ConName = "Mathew"
>
> Set objOL = CreateObject("outlook.application")
> Set myNS = objOL.GetNamespace("MAPI")
>
> If myNS.AddressLists("Contacts").AddressEntries(ConName).Name = ConName Then
> myNS.AddressLists("Contacts").AddressEntries(ConName).Delete
> End If
>
> Set myNS = Nothing
> Set objOL = Nothing
>
> End Sub
>
> If a contact name doesn't exist, then the next one is returned - hence the check...
>
> HTH,
> Bernie
> MS Excel MVP
>
>
> "Mathew" <(E-Mail Removed)> wrote in message
> news:C60F2B29-0CDB-45E1-A3D4-(E-Mail Removed)...
> >I have an excel spreadsheet that we keep our contacts in. Occasionally, we
> > need to replace one. When this happens, we just run a macro and it creates
> > the new contact in Outlook. Thanks to Gram Mayors template on this. But,
> > now we must go to Outlook and delete the old one. Not a problem for most
> > people, however, most of my co-workers are soon to be "Darwin Award Winners."
> > So, I've been tasked with developing a macro that will also delete the old
> > contact and create the new contact. As I said, I've got the code for the new
> > contact, but any ideas on how to delete a contact from Excel would be
> > welcomed. Thanks in advance for any help!

>
>
>

 
Reply With Quote
 
Mathew
Guest
Posts: n/a
 
      15th Apr 2008
Bernie: Thanks for the help. I got the problem solved!!



"Mathew" wrote:

> Bernie: Thanks for the help. However, the code did not function. I get a
> funny error: Run-Time Error -2147221233 (8004010f)': when the code reaches
> this line:
> If myNS.AddressLists("Contacts").AddressEntries(ConName).Name = ConName Then
> Another wrinkle is that I get a message saying that another program is
> trying to access Outlook and ask permission to allow this. I check Ok and
> the program still fails. Any ideas??
>
>
> "Bernie Deitrick" wrote:
>
> > Sub TryNow()
> > Dim objOL As Object
> > Dim myNS As Outlook.Namespace
> > Dim ConName As String
> >
> > ConName = "Mathew"
> >
> > Set objOL = CreateObject("outlook.application")
> > Set myNS = objOL.GetNamespace("MAPI")
> >
> > If myNS.AddressLists("Contacts").AddressEntries(ConName).Name = ConName Then
> > myNS.AddressLists("Contacts").AddressEntries(ConName).Delete
> > End If
> >
> > Set myNS = Nothing
> > Set objOL = Nothing
> >
> > End Sub
> >
> > If a contact name doesn't exist, then the next one is returned - hence the check...
> >
> > HTH,
> > Bernie
> > MS Excel MVP
> >
> >
> > "Mathew" <(E-Mail Removed)> wrote in message
> > news:C60F2B29-0CDB-45E1-A3D4-(E-Mail Removed)...
> > >I have an excel spreadsheet that we keep our contacts in. Occasionally, we
> > > need to replace one. When this happens, we just run a macro and it creates
> > > the new contact in Outlook. Thanks to Gram Mayors template on this. But,
> > > now we must go to Outlook and delete the old one. Not a problem for most
> > > people, however, most of my co-workers are soon to be "Darwin Award Winners."
> > > So, I've been tasked with developing a macro that will also delete the old
> > > contact and create the new contact. As I said, I've got the code for the new
> > > contact, but any ideas on how to delete a contact from Excel would be
> > > welcomed. Thanks in advance for any help!

> >
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i delete a macro in Excel 2003 when delete isn't highlight =?Utf-8?B?QWJlbA==?= Microsoft Excel Misc 2 13th Sep 2005 04:09 AM
how i find duplicate contact in Outlook and delete it ? =?Utf-8?B?TGVhcm5lcg==?= Microsoft Outlook Contacts 1 11th Nov 2004 12:31 PM
Re: copy outlook contact information to excel sheet with macro Dick Kusleika Microsoft Excel Programming 1 12th Aug 2004 11:21 PM
Importing Contact List from Excel to Contact in Outlook Orlando Microsoft Outlook Contacts 3 1st Aug 2004 09:43 PM
Chronic macro problem -How to delete an excel macro Todd Microsoft Excel Crashes 0 30th Jun 2004 05:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:11 AM.