- Alt+F11
- Insert > Module
- Past
macro.vbs
Last active
April 28, 2022 08:50
-
-
Save timendum/6731294d971c46c6315dfd76f95223b1 to your computer and use it in GitHub Desktop.
Remove big attachments from Outlook macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment