Outlook Macro to delete email from Sent Folder and Delete Folder

V

Vishal

Hi,

I have a macro given by someone which deletes a mail sent to a particular id
from Sent Folder and then permanently deletes it from the Delete Folder as
well. It was working fine earlier but now it doesn't ! When I run it says :

Compile error: Expected: end of statement

Please advise.

Thanks in advance,
-V

Macro
----------------------------------------------------------

VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "ThisOutlookSession"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True
Public WithEvents mySentItems As Outlook.Items
Attribute mySentItems.VB_VarHelpID = -1
Public WithEvents myDeletedItems As Outlook.Items
Attribute myDeletedItems.VB_VarHelpID = -1


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 = "IMG POC P2P SFEG ID" 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 = "IMG POC P2P SFEG ID" Then
OutgoingMail.Delete
End If

End Sub
 
S

Sue Mosher [MVP-Outlook]

Could you point out which code statement raises that error, please?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
V

Vishal

Hi Sue,

Thanks for offering help. It gives error at the very first statement on
CLASS:
VERSION 1.0 CLASS

Following statement as well as all the Attribute statements are highlighted
in red - Syntax error.

BEGIN
MultiUse = -1 'True
End

Thanks,
-V
 
S

Sue Mosher [MVP-Outlook]

I don't know why you're seeing those statements in VBA, but then again, we don't know what the other person actually gave you or what you did with it. The usable code begins at the first Public Public WithEvents statement.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top