Remove Attachments From Messages

Chia sẻ bởi:hands
★★★★★
Quảng cáo

Outlook doesn't have this functionality built in so you'll need to use an add-in or VBA, but yes, it can be done.
See [URL='www.slipstick.com/addins/auto-process/attachment-management-tools-for-outlook/']Attachment Management Tools for Outlook for add-ins or [URL='www.slipstick.com/developer/remove-attachments-from-messages/#more']More Information for additional macros, including code samples that can save the attachments to the hard drive before deleting them from the message.

This code will work with sent or received messages, in any folder. To use, [URL='www.slipstick.com/developer/how-to-use-outlooks-vba-editor/']add the code to the VBA editor, select the messages that you want to delete the attachment from and run it.

See [URL='www.slipstick.com/addins/auto-process/attachment-management-tools-for-outlook/']Attachment Management Tools for Outlook for add-ins or [URL='www.slipstick.com/developer/remove-attachments-from-messages/#more']More Information for additional macros, including code samples that can save the attachments to the hard drive before deleting them from the message.

This code will work with sent or received messages, in any folder. To use, [URL='www.slipstick.com/developer/how-to-use-outlooks-vba-editor/']add the code to the VBA editor, select the messages that you want to delete the attachment from and run it.

See [URL='www.slipstick.com/addins/auto-process/attachment-management-tools-for-outlook/']Attachment Management Tools for Outlook for add-ins or [URL='www.slipstick.com/developer/remove-attachments-from-messages/#more']More Information for additional macros, including code samples that can save the attachments to the hard drive before deleting them from the message.

This code will work with sent or received messages, in any folder. To use, [URL='www.slipstick.com/developer/how-to-use-outlooks-vba-editor/']add the code to the VBA editor, select the messages that you want to delete the attachment from and run it.

See [URL='www.slipstick.com/addins/auto-process/attachment-management-tools-for-outlook/']Attachment Management Tools for Outlook for add-ins or [URL='www.slipstick.com/developer/remove-attachments-from-messages/#more']More Information for additional macros, including code samples that can save the attachments to the hard drive before deleting them from the message.

This code will work with sent or received messages, in any folder. To use, [URL='www.slipstick.com/developer/how-to-use-outlooks-vba-editor/']add the code to the VBA editor, select the messages that you want to delete the attachment from and run it.

See [URL='www.slipstick.com/addins/auto-process/attachment-management-tools-for-outlook/']Attachment Management Tools for Outlook for add-ins or [URL='www.slipstick.com/developer/remove-attachments-from-messages/#more']More Information for additional macros, including code samples that can save the attachments to the hard drive before deleting them from the message.

This code will work with sent or received messages, in any folder. To use, [URL='www.slipstick.com/developer/how-to-use-outlooks-vba-editor/']add the code to the VBA editor, select the messages that you want to delete the attachment from and run it.

See [URL='www.slipstick.com/addins/auto-process/attachment-management-tools-for-outlook/']Attachment Management Tools for Outlook for add-ins or [URL='www.slipstick.com/developer/remove-attachments-from-messages/#more']More Information for additional macros, including code samples that can save the attachments to the hard drive before deleting them from the message.

This code will work with sent or received messages, in any folder. To use, [URL='www.slipstick.com/developer/how-to-use-outlooks-vba-editor/']add the code to the VBA editor, select the messages that you want to delete the attachment from and run it.

Sub DeleteAllAttachmentsFromSelectedMessages()
    Dim oAttachments       As Attachments
    Dim selItems            As Selection
    Dim oMsg              As Object
    Dim lngAttachmentCount  As Long

' Set reference to the Selection.
    Set selItems = ActiveExplorer.Selection

'  Loop though each item in the selection.
    For Each oMsg In selItems
        Set oAttachments = oMsg.Attachments

lngAttachmentCount = oAttachments.Count

' Loop through attachments until attachment count = 0.
        While lngAttachmentCount > 0
            oAttachments(1).Delete
            lngAttachmentCount = oAttachments.Count
        Wend

oMsg.Save
    Next

MsgBox "All Done. Attachments were removed.", vbOKOnly, "Message"

Set oAttachments = Nothing
    Set selItems = Nothing
    Set oMsg = Nothing
End Sub

Remove Attachments From Forwards

A user needed to forward a message, but without the attachment and with the attachment name in the message body.

As written, this works with a selected message, not an open message.

You will need to set a Reference to the Microsoft Word Object Model in Tools, References.vvvvv

Public Sub RemoveForward()
Dim oItem As MailItem
Dim oAtt As Attachment
Dim strAtt As String
Dim olInspector As Outlook.Inspector
Dim olDocument As Word.Document
Dim olSelection As Word.Selection

Set oItem = Application.ActiveExplorer.Selection.item(1)
strAtt = ""

For Each oAtt In oItem.Attachments
    strAtt = strAtt & "<<" & oAtt.FileName & ">> "
Next oAtt

Dim oMsg As MailItem
   Set oMsg = oItem.Forward
   oMsg.To = "alias@address"
   oMsg.Display

Set olInspector = Application.ActiveInspector()
    Set olDocument = olInspector.WordEditor
    Set olSelection = olDocument.Application.Selection

olSelection.InsertBefore strAtt

For Each oAtt In oMsg.Attachments
    oAtt.Delete
Next oAtt

Set oItem = Nothing
End Sub

How to Use Macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 and above, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it's at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or [URL='www.slipstick.com/developer/how-to-use-outlooks-vba-editor/']sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  • Right click on Project1 and choose Insert > Module
  • Copy and paste the macro into the new module.
  • Set a reference to the Word Object Model in the VBA editor's Tools, References dialog.
    cdn.slipstick.com/images/2012/06/word-object-model.png
  • Customize the ribbon or Quick Access Toolbar to add a button to the macro for easy access.

More information as well as screenshots are at [URL='www.slipstick.com/developer/how-to-use-outlooks-vba-editor/']How to use the VBA Editor

More Information
[URL='www.slipstick.com/addins/housekeeping-and-message-management-outlook/']Housekeeping and Message Management Tools for Outlook
[URL='www.slipstick.com/addins/housekeeping-and-message-management-for-exchange-server/']Housekeeping and Message Management Tools for Exchange Server
[URL='www.slipstick.com/outlook/email/how-to-save-email-in-windows-file-system/']How to Save Email Messages to the Windows File System

VBA: [URL='www.slipstick.com/developer/code-samples/save-and-delete-attachments/']Save Attachments to hard drive Can easily be tweaked to delete the attachment without saving it.

VBA: [URL='https://www.vboffice.net/en/developers/save-multiple-attachments-to-file-system']Attachments: Save the selection to the harddisk (VBOffice.net)
VBA: [URL='https://www.vboffice.net/en/developers/delete-multiple-attachments-at-once']Attachments: Delete the selection (VBOffice.net)
[URL='www.slipstick.com/developer/how-to-use-outlooks-vba-editor/']How to use VBA code samples
www.slipstick.com/developer/remove-attachments-from-messages/

Thiết kế Tổng đãi ngộ (Total Rewards) theo khung SHRM
Khóa học SprinGO phù hợp

Thiết kế Tổng đãi ngộ (Total Rewards) theo khung SHRM

Khóa học “Thiết kế Tổng phần thưởng (Total Reward) chuẩn khung SHRM” giúp bạn nắm vững toàn bộ hệ thống đãi ngộ theo chuẩn...

Xem khóa học
★★★★★ 5 ★ 1 👤 5 ▥ 0
Quảng cáo

Bạn nên đọc

Leave a Reply

Your email address will not be published. Required fields are marked *

Quảng cáo

Cũ vẫn chất

Xem thêm