Skip to content

Instantly share code, notes, and snippets.

@timendum
Last active April 28, 2022 08:50
Show Gist options
  • Save timendum/6731294d971c46c6315dfd76f95223b1 to your computer and use it in GitHub Desktop.
Save timendum/6731294d971c46c6315dfd76f95223b1 to your computer and use it in GitHub Desktop.
Remove big attachments from Outlook macro
Sub RemoveAllBigAttachments()
Dim objMail As Outlook.MailItem
Dim oMeet As Outlook.MeetingItem
Dim oAppt As Outlook.AppointmentItem
Dim oAttachments As Outlook.Attachments
Dim iCount As Long
Dim I As Long
'One and ONLY one message muse be selected
If Application.ActiveExplorer.Selection.Count <> 1 Then
MsgBox ("Select one and ONLY one message.")
Exit Sub
End If
If Application.ActiveExplorer.Selection.item(1).Class = OlObjectClass.olMail Then
Set objMail = Application.ActiveExplorer.Selection.item(1)
Set oAttachments = objMail.Attachments
ElseIf Application.ActiveExplorer.Selection.item(1).Class = OlObjectClass.olMeetingRequest Then
Set oMeet = Application.ActiveExplorer.Selection.item(1)
Set oAttachments = oMeet.Attachments
ElseIf Application.ActiveExplorer.Selection.item(1).Class = OlObjectClass.olAppointment Then
Set oAppt = Application.ActiveExplorer.Selection.item(1)
Set oAttachments = oAppt.Attachments
Else
Exit Sub
End If
iCount = oAttachments.Count
If iCount > 0 Then
For I = iCount To 1 Step -1
If oAttachments.item(I).Size > 500000 Then
oAttachments.item(I).Delete
End If
Next I
End If
End Sub
  1. Alt+F11
  2. Insert > Module
  3. Past macro.vbs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment