Attachment Issues

Embed a JPEG Image in an Excel VBA Email

Khadija KhanKhadija Khan Dec 2, 2026 869 views

Question details

Embed a JPEG banner in an HTML email sent by an Excel VBA macro so recipients do not need to load it from an external link.

Product
Microsoft Excel and Outlook
Device & OS
not provided
Scenario
A VBA macro creates an HTML email containing a JPEG banner.
Observed behavior
Recipients cannot always view the banner when the email references an external image link.
Before you start

Confirm that the JPEG file is available on the computer running the macro and note its full path. The example uses desktop Excel and classic Outlook for Windows with an Outlook account configured.

Solution 1Recommended

Attach the JPEG and reference it by Content-ID

Use an inline attachment instead of an external image URL when creating an Outlook email from Excel VBA.

1
Open the VBA editor

In Excel, press Alt+F11, then select Insert > Module to create a module or open the module containing your email macro.

2
Add the image and Content-ID

Add the following example to the module. Replace the recipient and JPEG path with your own values: Sub EmailWithBanner() Dim outlookApp As Object Dim mail As Object Dim banner As Object Set outlookApp = CreateObject("Outlook.Application") Set mail = outlookApp.CreateItem(0) Set banner = mail.Attachments.Add("C:\Images\banner.jpg") banner.PropertyAccessor.SetProperty _ "http://schemas.microsoft.com/mapi/proptag/0x3712001F", "BannerImage" With mail .To = "recipient@example.com" .Subject = "Email with banner" .HTMLBody = "<html><body><p>Hello,</p>" & _ "<img src=""cid:BannerImage"" alt=""Banner""></body></html>" .Display End With End Sub

3
Preview and test the message

Run EmailWithBanner from the VBA editor. Check the preview in Outlook, then click Send and verify the received message in your recipient's email client.

Attach the JPEG and reference it by Content-ID
Match the identifiers: The Content-ID set on the attachment must match the value after cid: in the HTML. Email clients may still handle inline images differently or restrict them.
Free Microsoft Office alternative

Work with Excel spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface and support for common Microsoft Office formats, making it easy to move everyday spreadsheet work. Outlook automation remains a Microsoft Office workflow.

Open and edit Microsoft Excel XLSX and XLS filesUse a familiar spreadsheet interface for everyday workbook tasksWork with spreadsheets in a lightweight, free office suiteReview workbook content before using a separate email workflow
microsoft office alternative - wps office

Frequently Asked Questions

Why use a Content-ID instead of an image URL?

A cid: reference points to an image attached to the message, so the recipient does not need to download the banner from an external website.

Why is my inline image not showing in the email?

Check that the JPEG path in Attachments.Add is valid and that the Content-ID set with PropertyAccessor exactly matches the value after cid: in HTMLBody. Also test the received message in the recipient's email client.

Can I send the email automatically instead of previewing it?

After testing the message, replace .Display with .Send in the VBA macro. Outlook or organizational security settings may affect automated sending.

Does this macro require Outlook?

Yes. The example uses Outlook.Application automation and is intended for classic Outlook for Windows with an account configured.