Consulting

Results 1 to 2 of 2

Thread: Not allow move to folder w/o containing certain text in subject line

  1. #1

    Not allow move to folder w/o containing certain text in subject line

    I am looking for some guidance on how to prevent an email from being moved to certain folders without certain text in the subject line. Ideally, adding a prompt to remind people that they need to add that text before moving it.

    The problem I'm trying to solve is we have a shared mailbox which folks need to work out of and then move a finished email to a Processed folder. Before they move it to the Processed folder it needs to have the ticket number included. We've noticed a lot of unworked emails getting moved to this Processed folder either intentionally or in error so working to prevent that in an automated way if possible.

    Using Outlook 2013

  2. #2
    If you add the following code to the ThisOutlookSession module of the VBA editor, and either restart Outlook (saving the code) or run the macro Application_Startup from the editor, if you move a message to the Processed folder (a sub folder of Inbox) and the text 'Ticket No:' is missing from the subject the user should get a prompt warning that the ticket number is missing and the message is opened to enable it to be edited.

    Option Explicit
    Private WithEvents Items As Outlook.Items
    
    Private Sub Application_Startup()
    Dim olNS As NameSpace
        Set olNS = GetNamespace("MAPI")
        Set Items = olNS.GetDefaultFolder(olFolderInbox).folders("Processed").Items
    lbl_Exit:
        Exit Sub
    End Sub
    
    Private Sub Items_ItemAdd(ByVal item As Object)
    Dim olFolder As Folder
        On Error GoTo ErrorHandler
        If InStr(1, item.Subject, "Ticket No:") = 0 Then
            MsgBox "Add the ticket number to the subject, or move the message back where it came from!"
            item.Display
        End If
    lbl_Exit:
        Exit Sub
    ErrorHandler:
        MsgBox Err.Number & " - " & Err.Description
        Err.Clear
        GoTo lbl_Exit
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

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