Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Delete an outlook contact using an Excel macro

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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Delete an outlook contact using an Excel macro

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(ConNa me).Name = ConName Then
myNS.AddressLists("Contacts").AddressEntries(ConNa me).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" wrote in message
...
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!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Delete an outlook contact using an Excel macro

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(ConNa me).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(ConNa me).Name = ConName Then
myNS.AddressLists("Contacts").AddressEntries(ConNa me).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" wrote in message
...
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!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Delete an outlook contact using an Excel macro

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(ConNa me).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(ConNa me).Name = ConName Then
myNS.AddressLists("Contacts").AddressEntries(ConNa me).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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel-Outlook Contact List [email protected] Excel Discussion (Misc queries) 1 July 9th 08 09:40 PM
Outlook contact linked to name in Excel bdesaul Excel Discussion (Misc queries) 2 January 28th 07 11:04 PM
Push Button in Outlook to Change Focus to Outlook Contact List Cole Excel Programming 0 October 25th 06 11:29 PM
create outlook contact from excel Trefor Excel Discussion (Misc queries) 2 September 21st 05 03:01 PM
copy outlook contact information to excel sheet with macro Dick Kusleika[_3_] Excel Programming 1 August 12th 04 11:21 PM


All times are GMT +1. The time now is 05:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"