Banner Ads - Top            

Code section - left navigation

VBA Code Samples

 

 

 

 

 

 

   

Save and Delete Attachments

The following is the Save Attachment code sample from Teach Yourself Outlook in 24 Hours.

Copy and paste the code from this page into your ThisOutlookSession project. To do this, click in the text box, Select All using Ctrl+A, Ctrl+C to copy.

In Outlook, press Alt+F11 to open the VBA editor and expand Microsoft Outlook Objects then double click on ThisOutlookSession to open it in the editing pane and Ctrl+P to paste the code.

To use, first create a folder under your My Documents named OLAttachments. Then select one or more messages and run the macro to save and remove the attachments. (May wish to comment out the line that deletes the attachment before testing). Remove or comment out the MsgBox lines after testing.

To delete the attachments without saving them, leave just these lines between the If... and End if. (The macro can also be edited to remove the statements above the If command that are no longer needed.)

 If lngCount > 0 Then
For i = lngCount To 1 Step -1

' Delete the attachment.
objAttachments.Item(i).Delete

Next i
objMsg.Save

End If