A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

VBA to delete message after reply



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old October 21st 08, 07:00 PM
DKY DKY is offline
Junior Member
 
First recorded activity at Outlookbanter: Oct 2008
Posts: 4
Default VBA to delete message after reply

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.
http://www.vboffice.net/sample.html?...cmd=showite m
After installing the code it turns the following red
Code:
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.

http://www.outlookcode.com/threads.a...essageid=28233

http://www.vbaexpress.com/forum/show...500#post163500
Ads
  #2  
Old October 22nd 08, 12:29 PM posted to microsoft.public.outlook.program_vba
Alan Moseley
external usenet poster
 
Posts: 61
Default VBA to delete message after reply

Try putting all of the code into the ThisOutlookSession code window rather
than a module window.

--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

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


"DKY" wrote:


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.
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.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.

http://www.outlookcode.com/threads.a...essageid=28233

http://www.vbaexpress.com/forum/show...500#post163500




--
DKY

  #3  
Old October 22nd 08, 04:59 PM
DKY DKY is offline
Junior Member
 
First recorded activity at Outlookbanter: Oct 2008
Posts: 4
Default

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 to move a message from my inbox to the deleted items when I reply to it.
  #4  
Old October 23rd 08, 09:06 AM posted to microsoft.public.outlook.program_vba
Alan Moseley
external usenet poster
 
Posts: 61
Default VBA to delete message after reply

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.
--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

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


"DKY" wrote:


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 to move
a message from my inbox to the deleted items when I reply to it.




--
DKY

  #5  
Old October 23rd 08, 02:00 PM
DKY DKY is offline
Junior Member
 
First recorded activity at Outlookbanter: Oct 2008
Posts: 4
Default

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
  #6  
Old October 23rd 08, 02:23 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default VBA to delete message after reply

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Alan Moseley" wrote in message
...
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.
--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

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


"DKY" wrote:


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 to move
a message from my inbox to the deleted items when I reply to it.




--
DKY


  #7  
Old October 23rd 08, 05:48 PM
DKY DKY is offline
Junior Member
 
First recorded activity at Outlookbanter: Oct 2008
Posts: 4
Default

Would your alternative suggestion of handline the Reply() event be something that's easily done? I'm not a programmer and found this code online so if not then I'm at a loss. Appreciate your suggestions.

Quote:
Originally Posted by Ken Slovak - [MVP - Outlook] View Post
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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Alan Moseley" wrote in message
...
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.
--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

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


"DKY" wrote:


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 to move
a message from my inbox to the deleted items when I reply to it.




--
DKY
  #8  
Old October 24th 08, 03:11 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default VBA to delete message after reply

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).

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"DKY" wrote in message
news

Would your alternative suggestion of handline the Reply() event be
something that's easily done? I'm not a programmer and found this code
online so if not then I'm at a loss. Appreciate your suggestions.


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Send A Reply Message Or Forward A Message Containing Stationary R. B. Houser Outlook - Installation 1 June 21st 07 06:10 AM
How to customize the fields of the Reply message of a new message Lotte Outlook - Using Forms 1 November 17th 06 07:27 PM
Get parent message (original) from the response created by Reply-All/Reply/Forward Sanjay Add-ins for Outlook 3 November 9th 06 05:02 PM
Cannot reply to message Marc Miller Outlook - General Queries 1 May 5th 06 08:17 PM
Message disapears when I reply or forward a message Duane Hubbard Outlook - General Queries 1 February 8th 06 05:56 PM


All times are GMT +1. The time now is 07:08 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.