How to Get a Warning When Adding Duplicate Attachments to Outlook Email

If you are annoyed that you frequently add the duplicate attachments to one email by mistake, you can use the method introduced in this article. It can make Outlook to auto check each attachment when you add it.

Many users must have ever encountered such a situation that the identical files get attached to an Outlook email repeatedly due to their incorrect operations or carelessness. For instance, if you have stored two identical files in two different local folders, when attaching files, you may mistakenly select and add both. Many may feel considerably annoyed at it. Therefore, in response to this issue, here we will teach you a quick method, which uses VBA to let Outlook automatically check each attachment’s name and size when you add it. Read on to get the elaborate steps and codes.

Get a Warning When Adding Duplicate Attachments to Outlook Email

Get a Warning When Adding Duplicate Attachments to Outlook Email

  1. In the first place, launch your Outlook program.
  2. Then press “Alt + F11” key buttons to access Outlook VBA editor.
  3. Next in the emerging window, double click the “ThisOutlookSession” project on the left side to open it.
  4. Subsequently, copy the following VBA codes into this project window.
Public WithEvents objInspectors As Outlook.Inspectors
Public WithEvents objMail As Outlook.MailItem

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

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
    'Only work on email
    If TypeOf Inspector.CurrentItem Is MailItem Then
       Set objMail = Inspector.CurrentItem
    End If
End Sub

Private Sub objMail_AttachmentAdd(ByVal objNewAttachment As Attachment)
    Dim objAttachments As Outlook.attachments
    Dim objAttachment As Outlook.Attachment
    Dim strFilePath As String
    Dim strFileName As String
    Dim strFileSize, strIndex As String
    Dim strMsg As String
    Dim nWarning As Integer
    Set objAttachments = objMail.attachments
    If objAttachments.Count > 0 Then
       For i = (objAttachments.Count - 1) To 1 Step -1
           Set objAttachment = objAttachments.Item(i)
           strFileName = objAttachment.filename
           strFileSize = objAttachment.Size
           'Compare the new attachment file name and size with the existing attachments'
           If (objNewAttachment.filename = strFileName) And (objNewAttachment.Size = strFileSize) Then
              strMsg = "You have attached this file - " & Chr(34) & objNewAttachment.filename & Chr(34) & "!" & vbCrLf & vbCrLf & "Do you still want to keep it?"
              nWarning = MsgBox(strMsg, vbYesNo + vbExclamation, "Find Duplicate and Identical Attachments")
              If nWarning = vbNo Then
                 Exit For
              End If
           End If
       Next i
    End If
End Sub

VBA Codes - Get a Warning When Adding Duplicate Attachments to Outlook Email

  1. After that, sign this code as usual.
  2. Later change your Outlook macro settings to allow signed macros.
  3. Finally restart your Outlook to activate the new VBA project.
  4. From now on, every time when you mistakenly add the identical attachment to an email, you will receive a warning, like the image below:Warning: Find Duplicate Attachments
  5. If you select “No”, the file will be deleted. But if “Yes”, it’ll be kept in Attached line.

Avert Irretrievable PST Data Corruption

Although PST file is prone to corruption, in most situations, you still can get back the corrupted PST data easily from your backups. However, if you haven’t backed up your PST data, what can do you then? Your last resort in that point is to recur to a potent repair tool, such as DataNumen Outlook Repair. Please bear in mind a fact that you shouldn’t trust in unreliable tool. Otherwise, you will tend to suffer irretrievable PST data loss.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including fix SQL Server and outlook repair software products. For more information visit

Comments are closed.