VBA Code for Sending an Email from Excel with Outlook

VBA & macros · Updated November 18, 2026

In Excel for Microsoft 365 on Windows, VBA can create an email through classic Outlook using Outlook’s object model. The example below opens a prepared message for review; change .Display to .Send only when you are ready to send it automatically.

How Excel VBA sends email

Excel does not send this message by itself. The macro asks the Outlook desktop application to create a mail item, fills in fields such as the recipient and subject, and then displays or sends that item. Outlook must be installed and configured with an account that can send mail. The code uses late binding, which means it creates Outlook objects at runtime rather than requiring you to select an Outlook reference in the VBA editor.

This approach is useful for routine messages based on spreadsheet data, such as a report notification or a reminder. It is not the same as sending directly from an SMTP server: Outlook handles the message using its configured account and policies. The account that sends the message is normally the default Outlook account unless you explicitly select another supported account.

Example VBA code for a draft email

In Excel, press Alt+F11 on Windows to open the Visual Basic Editor, choose Insert > Module, and paste in the macro. Replace the sample address, subject, and message with your own. The workbook does not need to be saved as a macro-enabled file merely to run code during the current session, but save it as an Excel Macro-Enabled Workbook (.xlsm) if you want to keep the macro.

Option Explicit

Sub CreateOutlookEmail()
    Dim OutlookApp As Object
    Dim OutlookMail As Object

    On Error GoTo ErrHandler

    ' Connect to Outlook or start it if it is not already open.
    Set OutlookApp = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApp.CreateItem(0)

    With OutlookMail
        .To = "recipient@example.com"
        .CC = ""
        .Subject = "Monthly report"
        .Body = "Hello," & vbCrLf & vbCrLf & _
                "The monthly report is ready for review." & vbCrLf & vbCrLf & _
                "Regards," & vbCrLf & Application.UserName

        ' Optional: use a complete file path for an attachment.
        ' .Attachments.Add "C:\Reports\MonthlyReport.xlsx"

        .Display   ' Opens the message so you can review it.
        ' Replace .Display with .Send to send without opening a draft.
    End With

CleanExit:
    Set OutlookMail = Nothing
    Set OutlookApp = Nothing
    Exit Sub

ErrHandler:
    MsgBox "Email could not be created: " & Err.Description, vbExclamation
    Resume CleanExit
End Sub

The macro uses Application.UserName for the sign-off, which is Excel’s configured user name; change that line if you want a fixed name or no sign-off. The attachment line is commented out so the example will not try to attach a file that may not exist on your computer.

Choose between displaying and sending

.Display opens a compose window containing the completed message. You can check the recipient, edit the text, add a signature, and click Send yourself. It is the safer choice while building or troubleshooting a macro. .Send submits the item through Outlook without opening that review window, so a mistaken address or incorrect content can be sent immediately.

For a macro that sends messages, first test with your own address and use .Display. Inspect the output, including line breaks and attachments. Only switch to .Send after adding suitable checks and confirming the message is correct. Sending automatically does not mean delivery is guaranteed: Outlook, the mail server, recipient filters, or organizational policy can still affect delivery.

Add recipients, attachments, and message text

The .To, .CC, and .BCC properties accept email addresses as text. Multiple addresses are commonly separated with semicolons. For example, set .CC = "manager@example.com; team@example.com". Verify the addresses that come from cells: blank cells, extra spaces, or a wrong row can create incomplete or misdirected mail. Avoid placing confidential recipients in a visible To or CC field when BCC is more appropriate.

Use .Attachments.Add with a full path to attach a file. For example, .Attachments.Add "C:\Reports\MonthlyReport.xlsx" expects that exact file to exist on the computer running Excel. A network drive letter may not be available to another user, and a file can be moved or renamed. A production macro should check that the file exists before adding it, and should tell the user clearly if it does not.

The example uses .Body, which creates plain-text content. It is usually the simplest and most dependable format for short messages. If you need formatted content, use .HTMLBody and supply valid HTML, for example paragraph and bold tags. HTML email requires attention to markup and encoding; do not put untrusted spreadsheet values into HTML without escaping them. Setting the HTML body may replace the body content that Outlook would otherwise use, including a default signature, so check the displayed result before sending.

Set up and run the macro safely

  1. Save a copy of the workbook before running a macro. VBA changes cannot be undone with Ctrl+Z, and a future version of the macro might change workbook data as well as create email.
  2. In Excel for Windows, open the Visual Basic Editor with Alt+F11, insert a standard module, and paste the code. The Mac keyboard shortcut differs by keyboard and Excel settings; use Tools > Macro > Visual Basic Editor if the shortcut is unavailable.
  3. Save the file as .xlsm if you need the macro to remain in the workbook. Reopen it only from a source you trust, and enable macros only when you understand what the code does.
  4. Run CreateOutlookEmail from the VBA editor or Excel’s macro list. With .Display, review the generated message and send it manually.

Excel’s macro security settings and your organization’s policies may block the code. Do not lower security broadly just to run an unknown workbook. If this macro is for a shared process, ask your IT administrator about approved macro signing, trusted locations, or supported automation methods.

Common problems and what they mean

  • “ActiveX component can’t create object” or a similar automation error: Excel cannot create the Outlook COM object. Check that classic Outlook for Windows is installed and that the installation is working. The new Outlook for Windows does not provide the same COM automation interface used by this example.
  • The message appears but does not send: If the code uses .Display, that is expected; click Send in the open message. If it uses .Send, check Outlook’s Outbox, connection status, account configuration, and any organization restrictions.
  • The attachment is missing: Confirm the full path is correct and accessible to the Windows account running Excel. Check the file name and extension, and make sure the file is not on a disconnected drive.
  • A security warning or send prompt appears: Outlook security behavior can depend on the Outlook version, installed antivirus status, and organization policy. Do not try to bypass a protective prompt; consult IT if an approved workflow needs unattended sending.
  • Code works for one person but not another: Outlook profile configuration, default account, permissions, file paths, and macro policies can differ between users. Test under the account and computer where the macro will actually run.

On a Mac, Excel VBA exists, but this Windows example relies on COM automation and CreateObject("Outlook.Application"), so it is not a cross-platform solution. Likewise, Outlook on the web cannot be automated by this VBA object-model code. If the workflow must support Mac users, web users, or the new Outlook, choose a supported alternative instead of assuming the same macro will work.

When VBA and Outlook are not the right fit

For a small, user-reviewed task on a Windows computer with classic Outlook, this method can be convenient. For a high-volume or unattended process, a desktop macro may be fragile: it depends on a particular computer, Outlook profile, user session, and local file access. It also needs safeguards against sending duplicate messages when a macro is run twice.

Consider a Microsoft Power Automate flow for supported cloud-based triggers and actions, or a centrally managed application that uses an approved Microsoft Graph integration. These options require appropriate licensing, permissions, and setup; they are not drop-in replacements for a workbook macro. For a simple one-off message, composing it directly in Outlook may be safer and faster than automating it.

Frequently Asked Questions

Can Excel VBA send an email without opening Outlook?
With .Send, the macro does not open a compose window, but this Outlook Object Model method still relies on Outlook being installed, configured, and available. It is not a way to send mail independently of Outlook or its account and security settings.

How do I send the email automatically?
In the example, replace .Display with .Send. Test first using your own address and verify recipients, subject, body, and attachments. Add checks to prevent sending when required fields are blank or when the intended file is missing.

Does this code work with the new Outlook for Windows?
No, this example uses Outlook’s COM automation object model, which is available with classic Outlook for Windows, not the new Outlook for Windows. Use a supported automation service or application interface for workflows that must work with the new Outlook.

Can I send to several people or include a file?
Yes. Separate multiple addresses in the To, CC, or BCC fields with semicolons, and use .Attachments.Add with the full path of an existing file. Review the message before sending to confirm the correct recipients and attachment.

Why does Outlook show a warning when VBA sends mail?
Outlook may apply security prompts or organizational controls to programmatic access, depending on the environment. The exact behavior varies with configuration. Do not disable protections to silence a warning; ask your administrator about an approved method for the task.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.