Delete All Attachments on Sent Items


I received that tweet a few days ago. Here’s the solution I put together for Rick.


This solution should work in all versions of Outlook from 2003 on.


Follow these instructions to add the code to Outlook.

  1. If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
  2. Copy the code from the code snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
  3. Click the diskette icon on the toolbar to save the changes
  4. Close the VB Editor
  5. Click File and select Options
  6. When the Outlook Options dialog appears click Trust Center then click the Trust Center Settings button
  7. Click Macro Settings
  8. Select either of the two bottom settings (i.e. Notifications for all macros or Enable all macros (not recommended; potentially dangerous code can run). The choice of which to choose is up to you. If you select Notifications, then you’ll be prompted at times to enable macros. If you pick Enable all then there’s a chance that a malicious macro could run. It’s a question of how much risk you want to assume.
  9. Click Ok until the dialog-boxes have all closed
  10. Close Outlook
  11. Start Outlook. Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run. Say yes.
Dim WithEvents olkSnt As Outlook.Items

Private Sub Application_Quit()
    Set objSnt = Nothing
End Sub

Private Sub Application_Startup()
    Set objSnt = Session.GetDefaultFolder(olFolderSentMail)
End Sub

Private Sub olkSnt_ItemAdd(ByVal Item As Object)
    Dim olkAtt As Outlook.Attachment, lngCnt As Long
    For lngCnt = Item.Attachments.count To 1 Step -1
        Set olkAtt = Item.Attachments(lngCnt)
        If Not IsHiddenAttachment(olkAtt) Then
        End If
    Set olkAtt = Nothing
End Sub

Private Function IsHiddenAttachment(olkAtt As Outlook.Attachment) As Boolean
    Dim olkPA As Outlook.PropertyAccessor, varTemp As Variant
    On Error Resume Next
    Set olkPA = olkAtt.PropertyAccessor
    varTemp = olkPA.GetProperty(PR_ATTACH_CONTENT_ID)
    IsHiddenAttachment = (varTemp <> "")
    On Error GoTo 0
    Set olkPA = Nothing
End Function

2 comments on “Delete All Attachments on Sent Items

    • Hi, Amit.

      My expertise is really with Outlook, not Excel and not extracting data from web sites. I might be able to help, but then again I may not be the right person. Tell me more about what it is you need to pull from the web site, what the web site looks like, and what you want to do with the extracted data. I can then tell you whether I can and will help or not.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s