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 the first place, start your Outlook program.
- Then you can switch to “Developer” tab and hit the “Visual Basic” button.
- Next you will get into Outlook VBA editor window.
- 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
- After that, you ought to confirm that your Outlook is set to allow macros.
- Optionally, if you frequently require this, you had better add the new macro to Quick Access Toolbar for future convenient check.
- 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.
- Immediately, all the embedded images will be changed to attachments as the following screenshot:
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


