Embed a JPEG Image in an Excel VBA Email
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.
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.
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.
In Excel, press Alt+F11, then select Insert > Module to create a module or open the module containing your email macro.
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
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.

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.

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.




