It is inevitable that at times you may move or delete any items mistakenly. Hence, in this article, we will expose you a way to let Outlook automatically warn you before you move or delete any items.
As we all know, we can simply drag and drop items to move them. Although it is quite convenient in most cases, it still can bring out some troubles. For instance, we can drag and drop an item to the wrong folders by accident. If you have many folders and items in your mailbox, it will be very difficult to bring the item back to its previous location. So, it will be better if you can get warned before moving any items.
Similarly, as Outlook can be set to warn you before you permanently delete any items, no warning for common “Delete”, you must desire that Outlook can warn no matter before you delete any items. In response to the two issues, here we will teach you how to achieve the warning via Outlook VBA.
Get Warned before Moving or Deleting Items
- At the very outset, launch your Outlook application.
- Then press “Alt + F11” keys to open Outlook VBA editor.
- Next you should open the “ThisOutlookSession” project.
- Subsequently, copy and paste the following VBA codes into this project.
'Take mail item as an example Public WithEvents objExplorer As Outlook.Explorer Public WithEvents objInspectors As Outlook.Inspectors Public WithEvents objMail As Outlook.MailItem Public strMsg As String Public nWarning As Integer Private Sub Application_Startup() Set objExplorer = Outlook.Application.ActiveExplorer Set objInspectors = Outlook.Application.Inspectors End Sub 'Get warned before moving Private Sub objExplorer_BeforeItemPaste(ClipboardContent As Variant, ByVal Target As MAPIFolder, Cancel As Boolean) strMsg = "Are you sure to move this email?" nWarning = MsgBox(strMsg, vbExclamation + vbYesNo, "Confirm Mail Movement") If nWarning = vbYes Then Cancel = False Else Cancel = True End If End Sub Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector) If Inspector.CurrentItem.Class = olMail Then Set objMail = Inspector.CurrentItem End If End Sub 'Get warned before deleting Private Sub objMail_BeforeDelete(ByVal Item As Object, Cancel As Boolean) strMsg = "Are you sure to delete this email?" nWarning = MsgBox(strMsg, vbExclamation + vbYesNo, "Confirm Mail Deletion") If nWarning = vbYes Then Cancel = False Else Cancel = True End If End Sub
- After that, sign this macro and change your Outlook macro settings to permit the signed macros.
- Eventually, you can restart your Outlook to activate the new VBA project.
- From now no, every time you move or delete any emails, you will get warned like the following image:
- The above code is taking email as an example. If you specify the other items, like tasks, you should use:
Public WithEvents objTask As Outlook.TaskItem
If Inspector.CurrentItem.Class = olTask Then Set objTask = Inspector.CurrentItem End If
Private Sub objTask_BeforeDelete(ByVal Item As Object, Cancel As Boolean)
The same holds true for appointments, contacts and so on.
- The “DeforeDelete” event can only work in an opened inspector.
Resolve Annoying Outlook Issues
In spite of boasting of multiple functions, you still can encounter multiple issues in your Outlook. Fortunately, Outlook comes preinstalled with a free PST fix tool, which can solve small troubles like a breeze. But, if problems are beyond what the inbox tool can do, you have no alternative but to recur to a more preeminent tool, such as DataNumen Outlook Repair.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupt SQL Server and outlook repair software products. For more information visit www.datanumen.com