Skip to content

Instantly share code, notes, and snippets.

@tdalon
Last active December 1, 2021 20:58
Show Gist options
  • Save tdalon/166c0542ef6d205dd1f8d271f83cfe58 to your computer and use it in GitHub Desktop.
Save tdalon/166c0542ef6d205dd1f8d271f83cfe58 to your computer and use it in GitHub Desktop.
Mark Emails Read and Complete with VBA
Public Sub Done()
Dim Items As VBA.Collection
Dim oItem As Object
Set Items = GetCurrentItems
For Each oItem In Items
If TypeOf oItem Is Outlook.MailItem Then
oItem.MarkAsTask (olMarkComplete)
oItem.UnRead = False
oItem.Save
End If
Next
End Sub
Function GetCurrentItems() As VBA.Collection
Dim c As VBA.Collection
Dim Sel As Outlook.Selection
Dim obj As Object
Dim i&
Set c = New VBA.Collection
If TypeOf Application.ActiveWindow Is Outlook.Inspector Then
c.Add Application.ActiveInspector.CurrentItem
Else
Set Sel = Application.ActiveExplorer.Selection
If Not Sel Is Nothing Then
For i = 1 To Sel.Count
c.Add Sel(i)
Next
End If
End If
Set GetCurrentItems = c
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment