VBA to delete message after reply

  • Thread starter Thread starter DKY
  • Start date Start date
D

DKY

I'm trying to find some VBA that will move the original message to th
deleted folder after I reply and have stumbled across this website.
http://tinyurl.com/65kjz9
After installing the code it turns the following red

Code
-------------------
Private WithEvents ReplyButton As Office.CommandBarButton
Private WithEvents m_Inspectors As Outlook.Inspector
-------------------

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.

http://www.outlookcode.com/threads.aspx?forumid=1&messageid=28233

http://www.vbaexpress.com/forum/showthread.php?p=163500#post16350
 
Try putting all of the code into the ThisOutlookSession code window rather
than a module window.
 
Thank you, now the red is gone but I'm not sure why the code doesn'
work. Maybe it's because I'm using Outlook 2007? Its supposed to mov
a message from my inbox to the deleted items when I reply to it
 
It certainly works on 2003, but only after you have saved the code and
restarted Outlook (as the button is only initialised at startup). I think
that your problem will be that you are clicking on the ribbon menu buttons to
reply, and I don't think that this code is designed to pick up the click
event of the ribbon button. I don't have a copy of 2003 so I am unable to
provide any further input on that.
 
I have Outlook 2007.
I had to restart outlook and save the code as you suggested. Also as
you suggested it doesn't work when I open the message and click reply
on the ribbon. Does anyone know how to modify the code to work when I
do that with Outlook 2007?
Code:
--------------------
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
--------------------
 
A ribbon click in Outlook 2007 would not trigger the CommandBarButton click
for Outlook 2003, as surmised. Working with the ribbon is not supported at
all in Outlook VBA code. The only way to work with the ribbon for Outlook
2007 is to use a COM addin.

An alternative might be to just handle the Reply() event for an item rather
than trying to respond to a button click.
 
Would your alternative suggestion of handline the Reply() event b
something that's easily done? I'm not a programmer and found this cod
online so if not then I'm at a loss. Appreciate your suggestions.

'Ken Slovak - [MVP - Outlook said:
;271848']A ribbon click in Outlook 2007 would not trigger th
CommandBarButton click
for Outlook 2003, as surmised. Working with the ribbon is not supporte
at
all in Outlook VBA code. The only way to work with the ribbon fo
Outlook
2007 is to use a COM addin.

An alternative might be to just handle the Reply() event for an ite
rather
than trying to respond to a button click.




"Alan Moseley" (e-mail address removed) wrote in message
It certainly works on 2003, but only after you have saved the cod
and
restarted Outlook (as the button is only initialised at startup).
think
that your problem will be that you are clicking on the ribbon men
buttons
to
reply, and I don't think that this code is designed to pick up th
click
event of the ribbon button. I don't have a copy of 2003 so I a
unable to
provide any further input on that.
--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


:
-

Thank you, now 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 t
move
a message from my inbox to the deleted items when I reply to it.
 
You have to know something to work with Reply. That's an event that fires
when an is replied to. If you want to also handle when someone clicks Reply
All you need to also handle the ReplyAll event.

You already are handling the NewInspector event, so you need to change your
Private m_Mail declaration to a WithEvents declaration. Then when an item is
opened check the Inspector.CurrentItem.Class property for olMail. If it's a
mail item assign m_Mail to that item. You would also do the same in the
Explorer.SelectionChange event if only 1 item is selected and it's a mail
item. To do that you need to declare an Explorers collection object
WithEvents and handle the SelectionChange event.

Then since your mail item object can handle events you handle Reply and
ReplyAll (and Forward if you want).
 
What would be awesome is if I could find some code that upon clicking the send button in a reply or forward it:
  1. checks my personal folders to see if a personal folder with the same name as that persons name
  2. if it doesn't exist then create it and upon creation set up auto archive settings
  3. 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?
 
Back
Top