PDA

View Full Version : Not allow move to folder w/o containing certain text in subject line



SimplyPsyke
09-26-2017, 01:53 PM
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

gmayor
09-27-2017, 05:40 AM
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