Skip to content

Instantly share code, notes, and snippets.

@hvmonteiro
Last active February 28, 2019 14:45
Show Gist options
  • Save hvmonteiro/6c0e05042a91f28c246fa2cebda6a3d3 to your computer and use it in GitHub Desktop.
Save hvmonteiro/6c0e05042a91f28c246fa2cebda6a3d3 to your computer and use it in GitHub Desktop.
Outlook macro to read selected items, clean up folder and archive items.
'Outlook VB Macro to Unread, CleanUp Folder & subFolders
' and Archive Selected items
Private Sub CleanUpAllFolders()
Dim objExpl As Explorer
Set objExpl = ActiveExplorer
objExpl.CommandBars.ExecuteMso ("ThreadCompressFolderRecursive")
End Sub
' Archive current selected conversation (when no individual items are selected)
' It works on collapsed and expanded conversations of emails
'
Private Sub ArchiveConversation()
On Error Resume Next
Set ArchiveFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders("Archive")
Set Conversations = ActiveExplorer.Selection.GetSelection(Outlook.OlSelectionContents.olConversationHeaders)
For Each Header In Conversations
Set Items = Header.GetItems()
For i = 1 To Items.Count
Items(i).UnRead = False
Items(i).Move ArchiveFolder
Next i
Next Header
End Sub
Sub execute()
result = MsgBox("Mark Items as Read and Archive?", vbYesNo)
If result = vbYes Then
Debug.Print ("Marking selected items as read, cleaning up folders anr archive emails.")
CleanUpAllFolders
ArchiveConversation
Else
MsgBox ("Canceled!")
End If
End Sub
@hvmonteiro
Copy link
Author

Outlook 2010

Description

This macro is specially useful when you have a lot of emails that are not directly meant for you to reply/follow, but rather for your team, and you want to Mark the Email or conversation thread as Read, Clean Up Folder & SubFolders (which will remove the unnecessary emails that have the same information) and Archive the email.

Usage

To use this macro you need to enable Development ribbon/toolbar and create a new Macro:

Activate Developer Toolbar

  1. Select File menu
  2. Select Options Item
  3. Select Customize tab
  4. Enable Developer item in Customize the Ribbon: items list
  5. Press OK button

The Developer toolbar will now be available in ribbon bar, among the Home, Send / Receive, Folder, View and Help.

Create the Macro

  1. Select the Developer Toolbar
  2. Press Visual Basic button
  3. Copy / Paste the contents of this code snippet into the editor
  4. Five a more meaningful name to the Macro Module in the VB Code Editor
  5. Save the macro and close the VB Code Editor

The new macro will now be available in the drop down Macros menu. If you select and email or conversation, and press the newly creatd macro on that menu, it will popup a message box asking if you want to clear the selected items.

Note: You can now also had the macro to a toolbar so that you can more quickly use it any time. Check Outlook Help on how to add custom buttons the the toolbars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment