[RESOLVED] Outlook - Delete Saved Messages
:confused: :confused: :confused: Newbie here...I need help and was wondering if anybody could give me a code sample. I am running Outlook 2003 and WinXP Home. I currently have an Outlook add-in that creates contacts via sent mail. Then I have a rule that sends a copy of a sent message with certain words in the subject to a specific folder. What I want to do is when a person responds to my initial email, (he would already be saved as a contact), I want that copy of the original message deleted. That way when I go to follow up to my initial contact, I am not sending a follow up email to someone that has already responded. I hope that I have done a good enough job of explaining this problem, PLEASE HELP ME! :( :(
Re: Outlook - Delete Saved Messages
Welcome to the Forums.
You would search the items collection of the mapifolder where your sent message copies are saved to. Then when found you can use
the .Delete method of the mailitem.
Search with my username and "Outlook" for many examples. :)
Re: Outlook - Delete Saved Messages
RobDog888, I have absolutely no programming experience, so I was wondering if there was some code sample that someone could post that could be inserted into ThisOutlookSession module that could help me. I know that is a huge favor for someone to write it for me, but it would be greatly appreciated. Thanks.
Re: Outlook - Delete Saved Messages
See my code in this thread. It moves the items as they are added to a folder but you just need to use the.Delete method instead and
change to point to the folder your wanting to monitor.
Re: Outlook - Delete Saved Messages
Re: Outlook - Delete Saved Messages
This will delete any message that comes into your Inbox folder with the matching criteria of "RE: ABC" in the message's subject.
VB Code:
'ThisOutlookSession
Option Explicit
Public WithEvents InboxItemsAdd As Items
Private Sub Application_MAPILogonComplete()
Set InboxItemsAdd = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub InboxItemsAdd_ItemAdd(ByVal Item As Object)
If Item.Subject = "RE: ABC" Then
Item.Delete
End If
End Sub
Re: Outlook - Delete Saved Messages
okay, but what if I want to delete all previous messages that i have sent to this person that are in folders other than the inbox? :confused:
Re: Outlook - Delete Saved Messages
You would need to do a .Find and if your sure you will only be returning corect results the you can loop theough the .Find and
.Delete each of them.
Re: Outlook - Delete Saved Messages
any code describing this .find method?
Re: Outlook - Delete Saved Messages
Find example from the help file...
VB Code:
Sub FindContact()
'Finds and displays last contacted info for a contact
Dim olApp As Outlook.Application
Dim objContact As Outlook.ContactItem
Dim objContacts As Outlook.MAPIFolder
Dim objNameSpace As Outlook.NameSpace
Set olApp = CreateObject("Outlook.Application")
Set objNameSpace = olApp.GetNamespace("MAPI")
Set objContacts = objNameSpace.GetDefaultFolder(olFolderContacts)
Set objContact = objContacts.Items.Find("[FileAs] = ""Smith, Jeff"" and [FirstName] = ""Jeff""")
If Not TypeName(objContact) = "Nothing" Then
MsgBox "Found"
Else
MsgBox "Contact not found."
End If
End Sub