Consulting

Results 1 to 3 of 3

Thread: Delete emails that have been replied to, via script

  1. #1
    VBAX Newbie
    Joined
    Feb 2009
    Posts
    2
    Location

    Delete emails that have been replied to, via script

    Hey Guys,

    I'm new to this forum so if i miss anything, apologizes.

    I am working in outlook 2003, my goal is to write a code to be able to delete a message once it has been replied to. I have archived this with the following code:-
    but now i need to edit this so it only works with a certain subject heading and not every email. Please help

    can the code be change so it deletes on predefined subject heading upon hitting reply. at the moment it is deleting any message that is replied to.

    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




    I am trying to change the following code so it only deleted

  2. #2
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    You'd need to update your event code so it checks the subject before deleting. Something like

    [VBA]Private Sub m_Inspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
    On Error Resume Next
    If Not m_Mail Is Nothing Then
    If m_Mail.Subject <> "Don't delete me!" Then
    m_Mail.Delete
    End If
    End If
    Set m_Mail = Nothing
    End If
    End Sub[/VBA]

  3. #3
    VBAX Newbie
    Joined
    Feb 2009
    Posts
    2
    Location
    Quote Originally Posted by JP2112
    You'd need to update your event code so it checks the subject before deleting. Something like

    [vba]Private Sub m_Inspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
    On Error Resume Next
    If Not m_Mail Is Nothing Then
    If m_Mail.Subject <> "Don't delete me!" Then
    m_Mail.Delete
    End If
    End If
    Set m_Mail = Nothing
    End If
    End Sub[/vba]
    perfect it works, thanks for the info. I had to make minor adjustments to make it work, changed the <> to = and there is one extra end if in the statement
    Private Sub m_Inspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
    On Error Resume Next
    If Not m_Mail Is Nothing Then
    If m_Mail.Subject = "Don't delete me!" Then
    m_Mail.Delete
    End If
    Set m_Mail = Nothing
    End If
    End Sub

Posting Permissions

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