Outlook

Print and delete emails; check for attachments before deleting

Ease of Use

Easy

Version tested with

2003 

Submitted by:

mdmackillop

Description:

Selected emails will be printed and deleted. If an email contains an attachment, the user will be asked to confirm deletion. 

Discussion:

Do I need to explain further? 

Code:

instructions for use

			

Option Explicit Public Sub PrintDelete() Dim objOL As Outlook.Application Dim objMsg As Outlook.MailItem Dim objAttachments As Outlook.Attachments Dim objSelection As Outlook.Selection Dim i As Long Dim lngCount As Long Dim Response As Integer Dim msg As String Dim strSubject As String ' Instantiate an Outlook Application object. Set objOL = CreateObject("Outlook.Application") ' Get the collection of selected objects. Set objSelection = objOL.ActiveExplorer.Selection ' Check selected item for attachments. For i = objSelection.Count To 1 Step -1 lngCount = objSelection(i).Attachments.Count If lngCount > 0 Then strSubject = objSelection(i).Subject If strSubject = "" Then msg = "Selected item #" & i Else msg = strSubject End If Response = MsgBox(msg & " has attachments." & vbCr _ & "Do you wish to delete?", vbYesNo) If Response = vbNo Then objSelection(i).PrintOut Else objSelection(i).PrintOut objSelection(i).Delete End If Else objSelection(i).PrintOut objSelection(i).Delete End If Next ExitSub: Set objAttachments = Nothing Set objMsg = Nothing Set objSelection = Nothing Set objOL = Nothing End Sub

How to use:

  1. Paste the code in a Standard Module within Outlook
  2. Assign a Button or Keyboard Shortcut to the macro.
 

Test the code:

  1. Select one or more dispensable emails, some of which contain attachments.
  2. Emails with no attachments will be printed and deleted.
  3. If an email contains an attachment, the prompt, containing the Subject (if any) or the Index (if none) will ask for confirmation.
  4. Select No to print but not delete.
  5. Save money by printing to a PDF printer!
 

Sample File:

No Attachment 

Approved by lucas


This entry has been viewed 114 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express