Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook VBA Macro to Delete Email from Sent and Delete Folder

Status
Not open for further replies.

PRUSA

Technical User
Sep 23, 2004
35
0
0
US
Hi Everyone,

I've been trying to find a solution for the following example, I send an email to "abc@gmail.com" once sent take the email from the sent folder move to delete folder and permanently delete the item. And this is for email only going to "abc@gmail.com"

I've looked around and the only code I could find is the following but its not working for me. I'm not sure if i have to create a class module, and regular module in vba.
Any help would be much appreciated.

Code:
Public WithEvents mySentItems As Outlook.Items
Public WithEvents myDeletedItems As Outlook.Items


Public Sub Application_Startup()

Set mySentItems = Outlook.Session.GetDefaultFolder(olFolderSentMail).Items
Set myDeletedItems = Outlook.Session.GetDefaultFolder(olFolderDeletedItems).Items

End Sub


Private Sub mySentItems_ItemAdd(ByVal Item As Object)
Dim OutgoingMail As Outlook.MailItem
Dim SentTo As String

Set OutgoingMail = Item
SentTo = OutgoingMail.To
Debug.Print Time
Debug.Print SentTo
If SentTo = "abc@gmail.com" Then
OutgoingMail.Delete
End If

End Sub


Private Sub myDeletedItems_ItemAdd(ByVal Item As Object)
Dim OutgoingMail As Outlook.MailItem
Dim SentTo As String

Set OutgoingMail = Item
SentTo = OutgoingMail.To
Debug.Print Time
Debug.Print SentTo
If SentTo = "abc@gmail.com" Then
OutgoingMail.Delete
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top