How to Batch Close a Specific Type of Open Items in Your Outlook

If you have opened a lot of all kinds of items in your Outlook, such as tasks, contacts, appointments and emails, etc., when you feel it messy, you may wish to quickly close a specific type of items. This article will help you achieve this function with ease.

When you keep too many items opened in Outlook meanwhile, you may find that Outlook cannot perform as smoothly or fast as normal. In this case, you may wish to close some items. My previous articles “How to Quickly Close All Open Items Except the Current One in Outlook” and “How to Quickly Close All Open Outlook Items by One Click” have introduced ways to close all items. But, at times, you may only hope to close a specific type of all open items, such as closing all open emails. In this case, you can use the following method to get it.

Batch Close a Specific Type of Open Items in Your Outlook

Batch Close a Specific Type of Open Items

  1. First off, follow the steps in “How to Run VBA Code in Your Outlook” to open Outlook VBA editor.
  2. Then, click “Insert” > “UserForm”.Insert UserForm
  3. In the “Toolbox” dialog box, select “ComboBox” and add one in the UserForm.Insert ComboBox
  4. Next, add two command buttons to the UserForm and change their captions to “Cancel” and “OK”, like the screenshot below.Add Command Buttons
  5. After that, right click the UserForm and choose “View Code”.View Code
  6. Subsequently, in the new screen, put the following code.
Private Sub UserForm_Initialize()
    With ComboBox1
        .AddItem "Emails"
        .AddItem "Appointments"
        .AddItem "Meetings"
        .AddItem "Contacts"
        .AddItem "Tasks"
        .AddItem "Notes"
        .AddItem "Journals"
    End With
End Sub

Private Sub CommandButton1_Click()
    lListIndex = ComboBox1.ListIndex
    Unload Me
End Sub

Private Sub CommandButton2_Click()
    Unload Me
End Sub

UserForm Code

  1. Later, copy the VBA code below into an unused module or project.
Public lListIndex As Long
Public objInspectors As Outlook.Inspectors
Public i As Long

Public Sub SelectType_CloseOpenItems()
    Set objInspectors = Outlook.Application.Inspectors
    If objInspectors.Count > 0 Then
 
       'Display the UserForm
       UserForm1.Show
 
       'Close the Specific Type of Items According to Your Choice in UserForm
       Select Case lListIndex
              Case 0
                   Call CloseSpecificTypeOfItems("MailItem")
              Case 1
                   For i = objInspectors.Count To 1 Step -1
                       If TypeOf objInspectors(i).CurrentItem Is AppointmentItem Then
                          If objInspectors(i).CurrentItem.MeetingStatus = olNonMeeting Then
                             objInspectors.Item(i).Close olSave
                          End If
                       End If
                   Next
              Case 2
                   For i = objInspectors.Count To 1 Step -1
                       If TypeOf objInspectors(i).CurrentItem Is AppointmentItem Then
                          If objInspectors(i).CurrentItem.MeetingStatus = olMeeting Then
                             objInspectors.Item(i).Close olPromptSave
                          End If
                       ElseIf TypeOf objInspectors(i).CurrentItem Is MeetingItem Then
                          objInspectors.Item(i).Close olSave
                       End If
                   Next
              Case 3
                   Call CloseSpecificTypeOfItems("ContactItem")
              Case 4
                   Call CloseSpecificTypeOfItems("TaskItem")
              Case 5
                   Call CloseSpecificTypeOfItems("NoteItem")
              Case 6
                   Call CloseSpecificTypeOfItems("JournalItem")
              End Select
        End If
     End Sub

Public Sub CloseSpecificTypeOfItems(strType As String)
     For i = objInspectors.Count To 1 Step -1
         If TypeName(objInspectors(i).CurrentItem) = strType Then
            objInspectors.Item(i).Close olSave
         End If
     Next
End Sub

VBA Code - Select Type & Close Items

  1. After that, add “SelectType_CloseOpenItems” macro to Quick Access Toolbar.Add Macro to Quick Access Toolbar
  2. Finally, you can try it.
  • Click the macro button in Quick Access Toolbar.
  • At once, the user form will pop up, in which you need to select a specific type of items.Select Type
  • For instance, I choose “Emails” here and click “OK”.
  • At once, all the opened emails will be closed.Close All Emails

Salvage Your Outlook Data in Time

It is always suggested to take actions as soon as you realize potential Outlook file corruption. For instance, if you receive the errors, like “PST file is inaccessible”, it requires you to try the inbuilt fix utility to repair PST issues. If unfortunately, this tool proves failed, you have no alternative but to take aid of an external tool. Yet, you should use reliable and experienced tool, such as DataNumen Outlook Repair. It has earned a lot of appreciates due to its high Outlook recovery rate.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including recover Sql Server and outlook repair software products. For more information visit www.datanumen.com

Comments are closed.