How to Auto Insert Information of the Attachment into Email Body When Removing It

This article will teach you how to use Outlook VBA to auto add the information of the email attachment into the message body when you remove the attachment.

In order to keep your Outlook mailbox in small size, avoiding PST corruption, it is highly suggested to save email attachments to local hard drive and remove them from Outlook. But removing attachments from emails will result in an issue. That is, in future, when you recheck an email and want to see its original attachments, you will find it difficult to remember and find its attachments in that there is not any information of the original attachments in the email. In this scenario, the best way is to add the information of the attachment into the body when you remove it. However, manually adding is quite troublesome. Therefore, here we will guide you how to us VBA to automate this operation. Read on to get the detailed steps and concrete VBA codes.

Auto Insert Information of the Attachment into Email Body When Removing It

Auto Insert Information of the Attachment into Email Body When Removing It

  1. In the first place, start your Outlook application.
  2. Then switch to “Developer” tab and click on “Visual Basic” button. If not find this tab, you can go to “Options” > “Customize Ribbon” to enable it firstly.
  3. Next in the popup VBA editor window, you should open “ThisOutlookSession” project window.
  4. Subsequently, you ought to copy and paste the following VBA codes into it.
Public WithEvents objInspectors As Inspectors
Public WithEvents objExplorer As Explorer
Public WithEvents objMail As MailItem

Private Sub Application_Startup()
    Set objInspectors = Outlook.Application.Inspectors
    Set objExplorer = Outlook.Application.ActiveExplorer
End Sub

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
    If TypeName(Inspector.CurrentItem) = "MailItem" Then
       Set objMail = Inspector.CurrentItem
    End If
End Sub

Private Sub objExplorer_SelectionChange()
    On Error Resume Next
    If TypeName(objExplorer.Selection.Item(1)) = "MailItem" Then
       Set objMail = objExplorer.Selection.Item(1)
    End If
End Sub

Private Sub objMail_AttachmentRemove(ByVal Attachment As Attachment)
    Dim strAttachmentInfo As String
 
    strAttachmentInfo = "<< " & Attachment.DisplayName & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & Attachment.Size & " KB >>" & " <br> ----------------------------------------------------- </br> " & strAttachment
    objMail.HTMLBody = "<HTML><BODY>Attachment Removed: " & strAttachmentInfo & "</HTML></BODY>" & objMail.HTMLBody
End Sub

VBA Codes - Auto Insert Information of the Attachment into Email Body When Removing It

  1. After that, you need to digitally sign this code.
  2. Later change your Outlook macro settings to allow signed macros.
  3. Finally you ought to restart your Outlook to activate the new project. From now on, Outlook will auto insert the information of the removed attachments into the message body, like the following image:Remove Attachments

Keep Calm Even If Outlook Crashes

As usual, if your Outlook tends to crash from time to time, it’s very likely that PST file will also tends to get corrupt. Therefore, you need to make a backup for your PST file on a regular basis. Otherwise, if you have no a current data backup when original PST proves corrupted, you will be required to attempt a tough PST repair, which will demand you to recur to a potent repair tool, like DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including sql damage and outlook repair software products. For more information visit www.datanumen.com

Comments are closed.