PDA

View Full Version : VBA to delete message after reply



DKY
10-21-2008, 11:02 AM
I'm trying to find some VBA that will move the original message to the deleted folder after I reply and have stumbled across this website where the code is.

' <DieseOutlookSitzung>
Option Explicit
Private WithEvents ReplyButton As Office.CommandBarButton
Private WithEvents m_Inspectors As Outlook.Inspectors
Private m_Mail As Outlook.MailItem

Private Sub Application_Startup()
Set ReplyButton = Application.ActiveExplorer.CommandBars.FindControl(, 354)
Set m_Inspectors = Application.Inspectors
End Sub

Private Sub m_Inspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
On Error Resume Next
If Not m_Mail Is Nothing Then
m_Mail.Delete
Set m_Mail = Nothing
End If
End Sub

Private Sub ReplyButton_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean _
)
On Error Resume Next

If TypeOf Application.ActiveWindow Is Outlook.Explorer Then
Set m_Mail = Application.ActiveExplorer.Selection(1)
Else
Set m_Mail = Application.ActiveInspector.CurrentItem
End If
End Sub
' </DieseOutlookSitzung>

After installing the code it turns the following red

Private WithEvents ReplyButton As Office.CommandBarButton
Private WithEvents m_Inspectors As Outlook.Inspectors
This code doesn't seem to work and I'm thinking the red may be why. Any help is greatly appreciated.

FYI I have also posted at the following websites.
outlookcode.com
outlookbanter.com

jfournier
10-21-2008, 11:49 AM
Do you have the code loaded into a class module or the ThisOutlookSession module? You can't have a variable declared WithEvents in a regular module...this may be causing the problem...

DKY
10-22-2008, 09:02 AM
Thank you, after moving the code to the 'ThisOutlookSession' section the red is gone but I'm not sure why the code doesn't work. Maybe it's because I'm using Outlook 2007? Its supposed to move a message from my inbox to the deleted items when I reply to it.

JKwan
10-22-2008, 09:11 AM
Thank you, after moving the code to the 'ThisOutlookSession' section the red is gone but I'm not sure why the code doesn't work. Maybe it's because I'm using Outlook 2007? Its supposed to move a message from my inbox to the deleted items when I reply to it.

Perhaps you are right. I tested it and after I reply, the email was deleted


Set ReplyButton = Application.ActiveExplorer.CommandBars.FindControl(, 354)


Check the above line, perhaps Outlook 2007 changed to reply button id?

DKY
07-06-2009, 08:20 AM
What would be awesome is if I could find some code that upon clicking the send button in a reply or forward it:

checks my personal folders to see if a personal folder with the same name as that persons name
if it doesn't exist then create it and upon creation set up auto archive settings
move the original message from my inbox to the new folder
This would probably however need to have different reply and forward buttons than the normal ones as I wouldn't want to do that on all email messages. Any thoughts?