How to Batch Embed All Images from a Windows Folder into an Outlook Email

This article will teach you how to batch embed all images in a Windows folder into the body of an Outlook email.

I’ve introduced how to quickly attach all files in a local folder to an Outlook email in my previous article – “3 Quick Methods to Attach All Files in a Local Folder to an Outlook Email”. Similar to that, at times, you may desire to quickly embed all images from a Windows folder into the body of an outlook email in batches. Thus, thereinafter, we will expose a piece of VBA code to help you achieve it.

Batch Embed All Images from a Windows Folder into an Outlook Email

Batch Embed All Images from a Windows Folder into an Email

  1. To start with, launch your Outlook program.
  2. After entering Outlook main screen, hit “Alt + F11” key buttons to access VBA editor.
  3. Then in the “Microsoft Visual Basic for Applications” window, you could open a module that is not in use.
  4. Next you ought to copy the VBA code below into this module.
Sub EmbedAllImages_fromWindowsFolder_toOutlookEmail()
    Dim objShell As Object
    Dim objLocalFolder As Object
    Dim strLocalFolder As String
    Dim strFile As String
    Dim objFileSystem As Object
    Dim strEmbedImage As String
    Dim objMail As Outlook.MailItem
    Dim objAttachments As Outlook.Attachments
    Dim objAttachment As Outlook.Attachment
    Dim i As Long
 
    Set objMail = Outlook.Application.ActiveInspector.CurrentItem
    Set objAttachments = objMail.Attachments
 
    'Select a source folder
    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("Shell.Application")
    Set objLocalFolder = objShell.BrowseForFolder(0, "Select the source Windows folder:", 0, "")
    strLocalFolder = objLocalFolder.self.Path & "\"
    'Get all files in this Windows folder
    strFile = Dir(strLocalFolder)
 
    i = 0
    While strFile <> ""
          'Find image files in the selected source folder
          Select Case LCase(objFileSystem.GetExtensionName(strFile))
                 Case "bmp", "gif", "jpg", "jpeg", "png"
 
                 'Add them to the current email
                 i = i + 1
                 objAttachments.Add strLocalFolder & strFile
                 Set objAttachment = objAttachments.Add(strLocalFolder & strFile)
 
                 objAttachment.propertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/proptag/0x3712001E", "item" & i
                 objMail.propertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8514000B", True
 
                 strEmbedImage = "<br /><img src=cid:item" & i & " align=baseline width='100'/>" & strEmbedImage
          End Select
          strFile = Dir
    Wend
 
    'Turn image attachments to inline images
    objMail.HTMLBody = "<HTML>" & "<BODY>" & strEmbedImage & "</BODY></HTML>"
End Sub

VBA Code - Batch Embed All Images from a Windows Folder into an Outlook Email

  1. After that, you could add the new VBA project to the Quick Access Toolbar or ribbon of Message window.
  • First open a new email.
  • Then click the down arrow in the Quick Access Toolbar.
  • From the drop down list, choose “More Commands” option.
  • In the popup window, add the macro to Quick Access Toolbar by taking the steps shown in the image below:Add the new VBA project to the Quick Access Toolbar
  1. Eventually, you can have a try.
  • In the Message window, hit the macro button in Quick Access Toolbar.
  • Then you would be required to select a source Windows folder.Select a source Windows folder
  • After clicking on “OK”, Outlook will begin to browse this Windows folder, find all image files and insert all of them into the current email body.

Easily Restore Outlook Data from Backups

Since crashes can occur to Outlook, it is advisable that we should make backups on a regular basis. With backups, you can retrieve your cherished Outlook data at will. Just open Outlook and head to “File” > “Open” > “Open Outlook Data File” to access the backups readily. However, if you have no backups, you should resort to a remarkable external tool like DataNumen Outlook Repair. It can fix PST issues and get back Outlook data with effortless ease.

Author Introduction:

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