To send an email with an attachment from Excel on Windows, use VBA to create a message through classic Outlook, add the file with Attachments.Add, and display the draft for review. The example below attaches the currently open workbook; it uses Outlook’s default sending account and does not send the message until you choose to replace .Display with .Send.
What the macro does
Excel VBA does not send this message directly. The code asks classic Outlook for an application object, creates an Outlook email item, fills in the recipient and message fields, and attaches a file from your computer. Outlook then handles the account, connection, and delivery. This is useful when Outlook is already part of your normal desktop workflow, but it means Outlook must be installed and set up on the computer running the macro.
The sample attaches ThisWorkbook.FullName, which is the full path and filename of the workbook containing the macro. It checks that the workbook has been saved and that the file is present before attempting to attach it. It then opens a draft, so you can check the address and attachment before sending.
VBA code to attach and draft the email
In Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic Editor. Choose Insert > Module, paste in this procedure, and change the recipient, subject, and body. Save a copy of the workbook before running a macro: macro actions cannot be undone with Ctrl+Z.
Sub DraftWorkbookEmail()
' Create a draft in classic Outlook with this workbook attached.
Dim olApp As Object
Dim olMail As Object
Dim attachmentPath As String
Dim recipient As String
recipient = "recipient@example.com"
If Len(ThisWorkbook.Path) = 0 Then
MsgBox "Save the workbook before creating the email.", vbExclamation
Exit Sub
End If
attachmentPath = ThisWorkbook.FullName
If Len(Dir$(attachmentPath)) = 0 Then
MsgBox "The workbook file could not be found.", vbExclamation
Exit Sub
End If
' Reuse Outlook if it is open; otherwise, start it.
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If olApp Is Nothing Then
Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0
If olApp Is Nothing Then
MsgBox "Classic Outlook could not be opened.", vbExclamation
Exit Sub
End If
Set olMail = olApp.CreateItem(0)
With olMail
.To = recipient
.Subject = "Monthly report"
.Body = "Hello," & vbCrLf & vbCrLf & _
"Please find the report attached." & vbCrLf & _
"Regards,"
.Attachments.Add attachmentPath
.Display
End With
End Sub
The Object declarations use late binding, so you do not need to select an Outlook library reference in the VBA editor. The numeric argument 0 to CreateItem means a mail item. The code’s error handling is limited to finding or starting Outlook; it shows a message if that fails rather than continuing with a missing application object.
Run it and check the draft
Return to Excel and run DraftWorkbookEmail from the VBA editor with F5, or use Developer > Macros, select the procedure, and choose Run. The draft should open in Outlook. Confirm the recipient, subject, message, and attachment name before sending it using Outlook’s normal Send button.
The example intentionally uses .Display. To send automatically, replace that line with .Send, but only after verifying the complete process with a test recipient. A macro using .Send can send immediately without showing the draft, and a mistaken address or stale file may be difficult to correct after delivery. Do not use automatic sending for bulk mail unless you have safeguards such as recipient validation, a test mode, and an explicit approval process.
Attach a different file or add recipients
To attach a report file rather than the workbook containing the macro, assign its full path to attachmentPath instead. For example, a path such as C:\Reports\MonthlyReport.pdf can be used if that file exists on the computer. Keep the file check, and remember that a path on your computer may not exist for another person or on a scheduled machine. Network drives and cloud-synced folders can also be unavailable or not yet synchronized when the macro runs.
For several recipients, Outlook’s .To, .CC, and .BCC properties accept address strings; separate multiple addresses with semicolons. For example, change the recipient assignment to a semicolon-separated list. Be careful with BCC and distribution lists: review the final recipient fields in the draft, especially when sending confidential material.
.Body creates a plain-text message. If you need formatted content, Outlook supports an HTML message body through .HTMLBody, which requires valid HTML and appropriate escaping of any text inserted from cells. A plain-text body is usually the simpler and safer choice for a short automated note.
Save the right version of the workbook
ThisWorkbook.FullName points to the saved workbook file, not a separate snapshot of unsaved edits. If the workbook has changed since its last save, the attachment may contain the previous saved version. Save the workbook before running the macro, then check the attachment in the draft. You can save manually with Ctrl+S on Windows; on a Mac, use Command+S. The sample does not save automatically, which avoids silently changing the file as part of sending an email.
If the workbook contains sensitive data, consider whether sending the whole workbook is appropriate. Hidden sheets, comments, metadata, formulas, and supporting data may remain in the file even if a visible report sheet looks harmless. A safer workflow may be to create and review a separate PDF or sanitized copy, then attach that output instead.
Outlook and platform requirements
This code uses Windows COM automation and is intended for Excel on Windows with classic Outlook installed and configured. It relies on the Outlook Object Model, which is available through classic Outlook. The new Outlook for Windows does not support this COM-based VBA automation in the same way, so installing or switching to new Outlook may make the code fail. If Outlook cannot be created, first confirm that classic Outlook is installed, opened, and has a configured mail account.
Excel for the web cannot run VBA macros. Excel for Mac also cannot run this Windows COM automation code as written; Outlook automation and available integration methods differ on Mac, so the Windows example should not be treated as cross-platform. For a process that must run in a browser or across different operating systems, consider a cloud workflow such as Power Automate, subject to the services and permissions available in your organization.
To make the Developer tab visible in Excel for Windows, go to File > Options > Customize Ribbon and select Developer. If the workbook is downloaded or received from someone else, Excel may block its macros. Review the file and its source before enabling anything. Do not turn on all macros globally merely to run one script; use your organization’s approved trusted-location or signing practices where applicable.
Common errors and how to diagnose them
- Outlook could not be opened: The code may be running on a computer without classic Outlook, Outlook may not be configured, or an organization policy may block automation. Check which Outlook version is installed and try opening it normally.
- The attachment is missing: Verify the full path, spelling, extension, and access permissions. For a workbook attachment, save it first. If using a network or synchronized folder, confirm it is available to the Windows account running Excel.
- The macro is blocked: Check Excel’s macro security notice and your organization’s policy. Only enable a macro when you trust its source and understand what it does. A blocked macro is not fixed by changing the email code.
- A security warning appears: Outlook’s security behavior can depend on its configuration, antivirus status, and organizational policies. A prompt is not necessarily a VBA syntax error. Do not attempt to bypass a security control; ask your administrator about an approved workflow.
- The draft uses an unexpected account: The sample creates a message using Outlook’s default account. If multiple accounts are configured, inspect the From field before sending. Selecting a specific sending account requires additional Outlook object-model code and should be tested in the target Outlook profile.
Safety and practical limits
Creating an email is an external action, so test with a harmless file and an address you control before using real recipients. A useful operational pattern is to keep the macro in draft mode, validate the recipient and attachment, and let a person approve sending. If you later automate sending, include checks for blank or malformed addresses, missing files, unexpected file sizes, and duplicate runs.
Outlook automation does not bypass account permissions, mail-server rules, attachment size limits, or data-loss prevention controls. Delivery can be rejected or delayed even when the VBA code successfully creates a message. For recurring or high-volume processes, a managed service or approved workflow is generally more reliable than a desktop macro that depends on a particular user’s Outlook profile being available.
Frequently Asked Questions
Can Excel VBA send an email without opening Outlook?
The example uses Outlook to create the message. It displays the draft, but Outlook may need to start in the background if it was not already open. VBA does not make this a direct Excel-to-email-server send. A service-based alternative may be more suitable for unattended workflows.
How do I attach a PDF instead of the Excel workbook?
Set attachmentPath to the PDF’s full path and keep the existence check. For example, the code can attach a file in a known Reports folder. Make sure the path is valid on the computer running the macro and inspect the draft to confirm the correct PDF is attached.
Can I send the email automatically?
Yes. Replace .Display with .Send to ask Outlook to send the message without opening the draft. Test carefully first, because a wrong recipient, attachment, or message could be sent immediately. Outlook and organizational security policies may still affect the operation.
Why does the code not work with new Outlook?
This procedure uses Outlook’s Windows COM automation interface, associated with classic Outlook. New Outlook does not provide that same COM automation support. Use classic Outlook for this specific approach, or choose a different integration that is supported in your environment.
Will the macro attach unsaved changes?
No. The example attaches the workbook file saved on disk. Save the workbook before running the macro if the attachment must include recent edits, then verify the attached file in Outlook’s draft.
Related
- Excel Table Data Sorting: Steps, Options, and Fixes
- Excel Spreadsheet Not Responding? Causes and Fixes
- Excel Suddenly Not Responding? Causes and Fixes
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Controller Macro Setup: Step-by-Step Guide for GamingTo set up a macro on a controller, connect a model that supports button sequences, open its official…
- How to Find VBA Code in Excel: Open and Search MacrosTo find VBA code in Excel for Microsoft 365 on Windows, open the workbook in the desktop app,…
- Excel VBA UserForm Option Button GroupsIn an Excel VBA UserForm, put related OptionButton controls inside the same Frame to make them a mutually…
- SteelSeries Macro Editor: Create and Assign MacrosTo use the SteelSeries Macro Editor, open SteelSeries GG, select a compatible device in Engine, choose a key…
- VBA AutoFilter: How to Filter Cells and Rows in ExcelIn Excel VBA, use the AutoFilter method on a range that includes the header row to filter records…
- Excel VBA Array Empty? How to Check If It Is AllocatedIn Excel VBA, IsEmpty does not reliably tell you whether an array has been allocated. For a dynamic…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.