VBA & Macro Problems

How to Paste Excel Formatting into an Email with VBA

Tauseeq MagsiTauseeq Magsi Oct 28, 2026 869 views

Question details

The user wants to automate copying a selected range in Excel and pasting it into an email body using VBA while preserving the original cell formatting.

Paste Excel Formatting into an Email Using VBA
Product
Excel
Device & OS
not provided
Scenario
Automating email reporting where formatted Excel tables need to be embedded directly in the email body.
Observed behavior
The user is looking for the correct VBA method to prevent the copied Excel data from being pasted as plain text.
Before you start

Ensure the Developer tab is enabled in your Excel ribbon and that you have added the 'Microsoft Outlook Object Library' reference in your VBA editor via Tools > References.

Solution 1Recommended

Use the HTMLBody Property in VBA

Convert the Excel range to HTML and assign it to the email's HTML body to retain colors, fonts, and borders.

By publishing the Excel range as a temporary HTML file and reading it back as a string, you can inject the exact formatting into the MailItem.HTMLBody property. This is the most reliable method for preserving complex Excel formatting in emails.

1
Open the VBA Editor

Press Alt + F11 to open the VBA Editor, then click Insert > Module to create a new script module.

2
Create an HTML Conversion Function

Write a custom function that uses the 'PublishObjects.Add' method to save your selected Excel range as an HTML file, and then reads the file into a text stream.

3
Draft the Email Script

Create your Outlook mail item script using 'CreateObject("Outlook.Application").CreateItem(0)'.

4
Assign the HTML Body

Set the '.HTMLBody' property of the mail item to include the output string from your HTML conversion function, then use '.Display' or '.Send'.

Use the HTMLBody Property in VBA
Manage Temporary Files: Remember to include code that uses the 'Kill' statement to delete the temporary HTML file from your system after the email is generated.
Free Microsoft Office alternative

Discover WPS Office for Your Spreadsheet Needs

While advanced VBA integrations with Outlook are specific to the Microsoft ecosystem, WPS Office provides a free, lightweight, and highly compatible alternative for all your daily spreadsheet tasks.

  1. 1. Download and Install WPS Office: Get the free WPS Office suite from the official website and install it on your device.
  2. 2. Open your Excel Workbook: Launch WPS Spreadsheet and open your existing .xlsx or .xlsm files with full compatibility.
  3. 3. Share via Email Easily: Use the built-in 'Share' or 'Export to PDF' features to quickly send your formatted spreadsheets via email without needing complex VBA scripts.
Free and lightweight alternative to Microsoft ExcelSeamless compatibility with .xls, .xlsx, and .xlsm formatsExport directly to PDF for easy email sharing without complex VBAFamiliar tabbed interface makes transitioning easy
microsoft office alternative - wps office

Frequently Asked Questions

Why does the .Body property strip my Excel formatting in VBA?

The .Body property in an Outlook MailItem only supports plain text. To retain fonts, colors, and table structures, you must use the .HTMLBody property or interact with the WordEditor object.

Do I need to enable specific references in the VBA editor to interact with Outlook?

Yes, if you are using early binding (declaring specific Outlook variable types), you must go to Tools > References in the VBA editor and check 'Microsoft Outlook Object Library'. If using late binding (CreateObject), this is not strictly required.

Can I send an Excel range as an attachment instead of pasting it?

Yes. You can use VBA to save the specific range or workbook as a new Excel file or a PDF, and then use the '.Attachments.Add' method in your MailItem script to attach the file.

Does WPS Office support VBA macros?

Yes, WPS Office supports VBA macros in its premium versions, providing a highly compatible environment for running your existing Excel scripts.