Excel VBA Send Email With Range of Cells: How-To
In this article
You can send a range of cells from Excel by email with VBA by building the range into an HTML string and passing it to Outlook's CreateItem method. The shortest working approach is: press Alt+F11, insert a module, paste a macro that reads your range with UsedRange or a named range, converts it to an HTML table, then calls Outlook.Application to create and display a mail item. This guide covers the exact code pattern, how to trigger it, and what to fix when Outlook blocks the send.
What You'll Need
- Microsoft Excel on Windows (the Outlook automation path below is Windows-only; Mac Excel cannot automate Outlook the same way).
- Microsoft Outlook installed and signed in on the same PC. The classic Outlook desktop app is required — the new Outlook for Windows does not expose the same COM automation interface, so
CreateObject("Outlook.Application")will fail there. - Macro security set to allow the workbook: File > Options > Trust Center > Trust Center Settings > Macro Settings. Choose "Disable all macros with notification" and click Enable Content when prompted, rather than enabling everything globally.
- A worksheet range you want to send — for example
A1:D20or a named range likeReportData.
Menu labels can differ slightly by Excel version, region and whether you are on Microsoft 365 or a perpetual release. The code itself is stable across Excel 2010 and later.
Step-by-Step
- Save your workbook as .xlsm. VBA code is stripped from .xlsx files. Use File > Save As and pick Excel Macro-Enabled Workbook.
- Open the VBA editor. Press Alt+F11 (or Developer > Visual Basic if the Developer tab is visible).
- Insert a standard module. In the editor, choose Insert > Module. Do not paste into a sheet module unless you specifically want a worksheet event to trigger it.
- Paste the macro. The example below reads a range, converts it to an HTML table, and opens a draft in Outlook. Adjust
rngAddress, the recipient and the subject.
TheSub EmailRange() Dim olApp As Object Dim olMail As Object Dim rng As Range Dim htmlBody As String Dim cell As Range Dim rowHtml As String Set rng = ThisWorkbook.Sheets("Sheet1").Range("A1:D20") htmlBody = "<table border='1' cellspacing='0' cellpadding='4'>" For Each cell In rng.Rows(1).Cells htmlBody = htmlBody & "<th>" & cell.Text & "</th>" Next cell htmlBody = htmlBody & "</tr>" For Each cell In rng.Offset(1, 0).Resize(rng.Rows.Count - 1, rng.Columns.Count).Cells If cell.Column = rng.Column Then htmlBody = htmlBody & "<tr>" htmlBody = htmlBody & "<td>" & cell.Text & "</td>" If cell.Column = rng.Column + rng.Columns.Count - 1 Then htmlBody = htmlBody & "</tr>" Next cell htmlBody = htmlBody & "</table>" Set olApp = CreateObject("Outlook.Application") Set olMail = olApp.CreateItem(0) With olMail .To = "recipient@example.com" .Subject = "Data from " & ThisWorkbook.Name .HTMLBody = "<p>See the table below.</p>" & htmlBody .Display End With Set olMail = Nothing Set olApp = Nothing End Sub.Displayline opens the draft so you can review it before sending. Change it to.Sendonly when you are confident the recipients and range are correct. - Run the macro. Place the cursor inside the subroutine and press F5, or go back to Excel and use Developer > Macros, select
EmailRange, and click Run. - Review the draft. Outlook opens a compose window with your table rendered as an HTML table. Check that headers, numbers and blank cells look right, then send.
- Attach the workbook instead if you prefer. Replace the
.HTMLBodyline with.Attachments.Add ThisWorkbook.FullNameto send the file itself rather than an inline table. Inline HTML is usually better for short ranges; attach the file for large ones. - Add error handling before you rely on it. Wrap the Outlook calls in
On Error GoTo Handlerand show a message box if Outlook is not running or the range is empty. A range with no data produces an empty email, which is easy to send by accident.
Common Mistakes
- Saving as .xlsx. The macro disappears the next time you open the file. Always use .xlsm.
- Using
.Valueinstead of.Text..Textrespects cell formatting such as currency and dates;.Valuecan show raw serial numbers for dates. - Forgetting HTML escaping. If a cell contains
&or<, the table breaks. Either escape those characters or accept that special characters may render oddly. - Trusting the new Outlook app. The new Outlook for Windows does not support the same COM automation, so
CreateObjectfails. Switch to classic Outlook or use a different method. - Hard-coding a sheet name that does not exist. Use
ActiveSheetor confirm the name matches exactly, including spaces. - Sending without review. A
.Sendcall runs immediately and cannot be recalled. Use.Displaywhile testing.
Tips
- Name your range (Formulas > Define Name) and reference it in code, so the macro keeps working when rows are added.
- Set
.BodyFormat = 2on the mail item to force HTML, which prevents the table appearing as plain text. - Loop over multiple recipients by building a string with semicolons, or loop the whole block once per address.
- Keep the range small. Very large HTML tables can be clipped by email clients; attach the workbook for anything over a few hundred rows.
- Store the recipient list on a hidden sheet rather than in the code so non-technical users can update it.
Troubleshooting
If that did not work, check the simplest causes first. Confirm Outlook is open and signed in, then confirm the workbook is saved as .xlsm and macros are enabled. If you get a "Run-time error 429" or "ActiveX component can't create object", Outlook is not registered or you are on the new Outlook app — close it, open classic Outlook, and retry. If Outlook shows a security prompt about a program accessing your address book, that is normal; approve it only for macros you wrote or trust.
If the email opens but the table is blank, your range reference is wrong or the sheet name is misspelled. If the table shows raw numbers for dates, switch from .Value to .Text. If the macro runs but nothing appears, check that Outlook is not minimised behind Excel and that no modal dialog is waiting.
If the send fails with a permissions error, your organisation may block programmatic sending. In that case, keep .Display and send manually. Do not attempt to bypass security prompts.
Frequently Asked Questions
Can I send to multiple recipients at once?
Yes. Set .To to a semicolon-separated string such as "a@example.com; b@example.com".
Does this work on Mac Excel?
Not with the same code. Mac Excel cannot automate Outlook through CreateObject in the same way, so the Windows pattern above will fail.
Can I send the workbook as an attachment instead?
Yes. Use .Attachments.Add ThisWorkbook.FullName in place of the HTML body line.
Why does the email show plain text instead of a table?
The mail item is defaulting to plain text. Set .BodyFormat = 2 before assigning .HTMLBody.
Will this work with Gmail instead of Outlook?
Not directly. The code targets Outlook's COM interface. Sending through Gmail requires a different approach such as SMTP with a configured server, which is outside this macro.
Can I schedule the email?
You can set .DeferredDeliveryTime on the mail item, but the draft still needs Outlook running at that time. For reliable scheduling, send it from Outlook itself after the macro creates the draft.