Consulting

Results 1 to 5 of 5

Thread: VBA to delete message after reply

  1. #1
    VBAX Regular
    Joined
    May 2008
    Posts
    11
    Location

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

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

  3. #3
    VBAX Regular
    Joined
    May 2008
    Posts
    11
    Location
    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.

  4. #4
    VBAX Expert
    Joined
    Aug 2004
    Posts
    812
    Location
    Quote Originally Posted by DKY
    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

    [VBA]
    Set ReplyButton = Application.ActiveExplorer.CommandBars.FindControl(, 354)
    [/VBA]

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

  5. #5
    VBAX Regular
    Joined
    May 2008
    Posts
    11
    Location
    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?
    Last edited by DKY; 07-06-2009 at 08:40 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •