Send an Excel Range in an Outlook Email and Attach Another Sheet
Question details
The user needs a VBA macro that puts a range from Sheet1 in an email body and attaches Sheet2 to the same message.

- Product
- Microsoft Excel and Microsoft Outlook
- Device & OS
- not provided
- Scenario
- Create an Outlook email from Excel with a formatted worksheet range in the body and a separate worksheet as an attachment.
- Observed behavior
- The desired message contains the Sheet1 range in the body and a workbook containing Sheet2 as an attachment.
The macro below requires desktop Excel and classic Outlook for Windows, with an Outlook account configured. Check the sheet names, the range to include, and the recipient address before running it.
Use VBA to email a range and attach a copied sheet
Publish the range as HTML, save Sheet2 as a temporary workbook, and send both through Outlook.
The example uses late binding, so you do not need to add Outlook or FileSystemObject references in the VBA editor. It sends the message immediately; replace .Send with .Display if you want to review it, but keep the temporary attachment until after you send or discard the displayed message.
In desktop Excel, open the workbook containing Sheet1 and Sheet2. Press Alt+F11, then choose Insert > Module.
Paste the following code into the module: Option Explicit Sub EmailRangeAndSheet() Dim sourceBook As Workbook, attachmentBook As Workbook Dim outlookApp As Object, message As Object, fso As Object Dim attachmentPath As String, htmlBody As String Dim oldAlerts As Boolean, errorText As String On Error GoTo Failed oldAlerts = Application.DisplayAlerts Set sourceBook = ThisWorkbook Set fso = CreateObject("Scripting.FileSystemObject") attachmentPath = fso.BuildPath(Environ$("TEMP"), _ fso.GetBaseName(fso.GetTempName) & ".xlsx") htmlBody = RangeToHTML(sourceBook.Worksheets("Sheet1").Range("A1:D10")) sourceBook.Worksheets("Sheet2").Copy Set attachmentBook = ActiveWorkbook Application.DisplayAlerts = False attachmentBook.SaveAs Filename:=attachmentPath, FileFormat:=xlOpenXMLWorkbook attachmentBook.Close SaveChanges:=False Set attachmentBook = Nothing Application.DisplayAlerts = oldAlerts Set outlookApp = CreateObject("Outlook.Application") Set message = outlookApp.CreateItem(0) With message .To = "recipient@example.com" .Subject = "Worksheet report" .HTMLBody = htmlBody .Attachments.Add attachmentPath .Send End With GoTo Cleanup Failed: errorText = Err.Description Cleanup: On Error Resume Next If Not attachmentBook Is Nothing Then attachmentBook.Close SaveChanges:=False Application.DisplayAlerts = oldAlerts If Len(attachmentPath) > 0 Then Kill attachmentPath On Error GoTo 0 If Len(errorText) > 0 Then MsgBox "Email not completed: " & errorText, vbExclamation End Sub Function RangeToHTML(sourceRange As Range) As String Dim tempBook As Workbook, tempSheet As Worksheet Dim fso As Object, textFile As Object Dim htmlPath As String, result As String, errorText As String On Error GoTo Failed Set fso = CreateObject("Scripting.FileSystemObject") htmlPath = fso.BuildPath(Environ$("TEMP"), _ fso.GetBaseName(fso.GetTempName) & ".htm") Set tempBook = Workbooks.Add(xlWBATWorksheet) Set tempSheet = tempBook.Worksheets(1) sourceRange.Copy With tempSheet.Range("A1") .PasteSpecial xlPasteValues .PasteSpecial xlPasteFormats .PasteSpecial xlPasteColumnWidths End With Application.CutCopyMode = False tempBook.PublishObjects.Add(xlSourceRange, htmlPath, tempSheet.Name, _ tempSheet.UsedRange.Address, xlHtmlStatic).Publish True Set textFile = fso.OpenTextFile(htmlPath, 1, False, -2) result = textFile.ReadAll textFile.Close Set textFile = Nothing GoTo Cleanup Failed: errorText = Err.Description Cleanup: On Error Resume Next If Not textFile Is Nothing Then textFile.Close If Not tempBook Is Nothing Then tempBook.Close SaveChanges:=False If Len(htmlPath) > 0 Then Kill htmlPath Application.CutCopyMode = False On Error GoTo 0 If Len(errorText) > 0 Then Err.Raise vbObjectError + 1000, "RangeToHTML", errorText RangeToHTML = result End Function
In the code, change Sheet1, Sheet2, A1:D10, the recipient, and the subject as needed. Save the workbook as a macro-enabled .xlsm file, then press Alt+F8, select EmailRangeAndSheet, and choose Run.

Work with Excel files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing spreadsheet files. Its Microsoft Office format support makes it easier to move existing documents into your workflow; it does not fix Excel or Outlook VBA automation.

Frequently Asked Questions
How do I change the range included in the email?
In the VBA module, replace Range("A1:D10") with the desired address and change "Sheet1" if your source sheet has a different name.
Can I review the Outlook message before sending it?
Replace .Send with .Display in the message block. If you do this, adjust the cleanup so the temporary attachment remains available until you have sent or discarded the message.
Why is Sheet2 copied to a separate workbook?
Outlook attaches files rather than individual Excel sheets. Worksheets("Sheet2").Copy creates a workbook that the macro can save and attach.
Will the attached workbook contain macros?
No. The example saves the copied sheet as an .xlsx file, which does not retain VBA code. Test the attachment separately if the sheet depends on macros or other worksheets.
Does this macro work with the new Outlook for Windows?
The example uses Outlook COM automation through CreateObject("Outlook.Application") and requires classic Outlook for Windows. It is not designed for the new Outlook.




