How to Quickly Convert All Embedded Images to Attachments in Your Outlook Email

If you would like to quickly change all the pictures embedded in message body to email attachments, you do not need to manually remove and re-attach. You can just use the piece of VBA code exposed in this article.

Sometimes, you may wish to batch turn all embedded images to attachments. For instance, too many pictures in the message body will interrupt your reading the texts in the body. Therefore, you want to remove them from email body and add them as attachments instead. Of course, you can manually do this. But it must be handier if any tools or VBA codes can get this in one go. Here we will unveil such a VBA code to you.

Quickly Convert All Embedded Images to Attachments in Your Outlook Email

Quickly Convert All Embedded Images to Attachments

  1. In the first place, start your Outlook program.
  2. Then you can switch to “Developer” tab and hit the “Visual Basic” button.
  3. Next you will get into Outlook VBA editor window.
  4. Subsequently, you need to copy the following VBA code into a blank module.
Sub TurnEmebeddedImagestoAttachments()
    Dim objMail As Outlook.MailItem
    Dim objAttachments As Outlook.attachments
    Dim objAttachment As Outlook.Attachment
    Dim objFileSystem As Object
    Dim strTempFolder As String
    Dim strFile As String
    Dim i As Long
 
    Select Case Outlook.Application.ActiveWindow.Class
           Case olInspector
                Set objMail = ActiveInspector.CurrentItem
           Case olExplorer
                Set objMail = Application.ActiveExplorer.Selection.Item(1)
    End Select

    Set objAttachments = objMail.attachments
 
    'Create a temp folder
    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
    strTempFolder = objFileSystem.GetSpecialFolder(2).Path & "\Temp " & Format(Now, "YYYY-MM-DD hh-mm-ss")
    MkDir (strTempFolder)
 
    'Save all embedded images to temp folder
    For i = objAttachments.Count To 1 Step -1
        Set objAttachment = objAttachments.Item(i)
        If IsEmbedded(objAttachment) = True Then
           objAttachment.SaveAsFile strTempFolder & "\" & objAttachment.FileName
        End If
    Next
 
    'Add extracted images as attachments
    strTempFolder = strTempFolder & "\"
    strFile = Dir(strTempFolder)
 
    While Len(strFile) > 0
          objMail.attachments.Add (strTempFolder & strFile)
          strFile = Dir
    Wend
 
    'Remove embedded images from message body
    With objMail
        .BodyFormat = olFormatPlain
    End With
End Sub

Function IsEmbedded(objCurAttachment As Outlook.Attachment) As Boolean
    Dim objPropertyAccessor As Outlook.PropertyAccessor
    Dim strProperty As String
 
    Set objPropertyAccessor = objCurAttachment.PropertyAccessor
    strProperty = objPropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E")
 
    If InStr(1, strProperty, "@") > 0 Then
       IsEmbedded = True
    Else
       IsEmbedded = False
    End If
End Function

VBA Code - Convert All Embedded Images to Attachments

  1. After that, you ought to confirm that your Outlook is set to allow macros.
  2. Optionally, if you frequently require this, you had better add the new macro to Quick Access Toolbar for future convenient check.
  3. Eventually you can have a try. Select or open an email and then run the macro by clicking the new macro button in Quick Access Toolbar.
  4. Immediately, all the embedded images will be changed to attachments as the following screenshot:Effects: Embedded Images to Attachment

Tricks for Protecting Your Valuable Outlook Data

As we all know, Outlook PST file is the same vulnerable as common files, such as Word documents or Excel spreadsheets. Therefore, you should keep watching out for all risks around your PST file, like viruses or improper handlings. So you need to make regular data backups for your PST file. Also, if you can afford it, it is wise to keep a robust Outlook repair tool handy, 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 recover mdf and outlook repair software products. For more information visit www.datanumen.com

5 responses to “How to Quickly Convert All Embedded Images to Attachments in Your Outlook Email”

  1. I have found that this no longer work in one of my mailboxes for the .jpg inline files. This I found from the debugger that the .jpg file item in the attachment object has size 0. And this end up giving me the runtime error with object not available for saveas.
    Do you know of any settings or a workaround for this issue?

  2. Jack,

    I’m not sure if you’re on the latest Outlook also for Microsoft 365, but I’ve done more extensive testing with this and confirm it still works well for me, there’s a few things you’ll need to check that might not be mentioned in depth here, but it’s best to use from the Quick Access bar still. I tried to combine other code to save the images after they’ve been converted but that’s another story and will see if I can combine them still for our purposes, but the catch is that it works on the currently-selected message, so kind of defeats the whole purpose of automating it.

    For the Inline Images script, ensure “Enable all Macros” is checked in Trust Center
    Also this only works on Cached Exchange mode in Outlook and not Online mode (found this out the hard way)
    Check you’re in Cached Mode by heading to File > Account Settings Twice > Double click your entry > Check the box, set it to “2 weeks” or similar
    Use from the Quick Access toolbar with the original code from here, it still works. Use Alt+F11 to quickly enter the code also.
    Right click Outlook’s ribbon to head to “Customise the Ribbon..”
    Go to Choose commands from: Macros
    It should display there
    Make a New Group on the right called “Convert” or so
    Add the Macro into there
    Also rename and choose a fun icon if you want 🙂
    Make sure to have the email selected you want this to work on (Reading Pane helps with testing too; enable this through View > Reading Pane > Right)

    Let me know if all that works, it does for me!

  3. This works well from Quick-Actions, though is it possible to adapt this for use in a Macro in Outlook Rules instead?

    We have New Starter emails and often the pictures are in-line. I’d want to run this rule automatically to ensure the in-line pics are converted to attachments, so another rule can then run to save these to a certain folder.

    Currently, both functionalities need to be done either from the Quick Access menu while the message is selected, or manually running the rule to save the attachments.

    Thanks!

  4. This macro no longer works. The photos just disappear. Such a shame & takes so long to save and then reattach…

Leave a Reply

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