VBA Send Mail from Excel: Outlook Setup and Code Guide

VBA & macros · Updated November 18, 2026

Yes. In Excel for Microsoft 365 on Windows, VBA can create and send an email through classic Outlook using Outlook’s object model. The usual approach is to create a MailItem, fill in its recipients and message, then use .Display to review it or .Send to send it.

How VBA email automation works

Excel VBA does not normally deliver an email directly to a mail server. Instead, a macro asks Outlook to create and handle a message. Outlook supplies the account, connection, and sending process, so a working Outlook profile is generally required. This is useful when a workbook already contains report data and you want to prepare an email without copying information by hand.

The key objects are the Outlook application and a mail item. VBA creates or connects to Outlook, creates a new message, sets properties such as To, Subject, and Body, and then displays or sends it. The example below uses late binding: variables are declared as Object, so you do not need to add an Outlook library reference in the VBA editor.

Using Outlook is different from sending email directly through SMTP. SMTP automation requires server and authentication details, which may be restricted by an organization. Outlook automation uses the profile and policies already configured in the desktop Outlook application.

Requirements and version limitations

The code in this guide is for Excel on Windows with classic Outlook installed and configured. A recipient address and a valid Outlook profile are also needed. If Outlook asks you to choose a profile, sign in, or finish setup, resolve that in Outlook before running the macro.

  • Classic Outlook for Windows: Supports the Outlook Object Model used by this VBA approach.
  • New Outlook for Windows: Does not support this traditional COM-based VBA automation. Switching from classic Outlook to new Outlook can therefore break a macro that previously created messages.
  • Excel for the web: Does not run VBA macros. Open the workbook in the desktop Excel application to use this method.
  • Excel and Outlook for Mac: The Windows COM automation code below does not work on Mac. Outlook for Mac does not expose the same Windows Outlook Object Model automation interface; use a Mac-compatible workflow instead.

To add a macro in desktop Excel for Windows, open the workbook and press Alt+F11 to open the Visual Basic Editor. Choose Insert > Module, then paste the code into the module. If the Developer tab is hidden, enable it through File > Options > Customize Ribbon and select Developer. Save a macro-enabled workbook as .xlsm if you need to keep the VBA code.

A starter macro that opens an email

This example prepares a plain-text message and displays it for review rather than sending it immediately. Replace the sample address and message with your own. Because it uses late binding, it does not require selecting an Outlook reference under Tools > References.

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

    On Error GoTo ErrorHandler

    ' Start Outlook or connect to its running instance.
    Set OutlookApp = CreateObject("Outlook.Application")
    Set MailItem = OutlookApp.CreateItem(0)

    With MailItem
        .To = "recipient@example.com"
        .Subject = "Monthly report"
        .Body = "Hello," & vbCrLf & vbCrLf & _
                "Please see the monthly report details." & vbCrLf & _
                "Regards"
        .Display
    End With

    Set MailItem = Nothing
    Set OutlookApp = Nothing
    Exit Sub

ErrorHandler:
    MsgBox "The email could not be created: " & Err.Description, vbExclamation
    Set MailItem = Nothing
    Set OutlookApp = Nothing
End Sub

The argument 0 passed to CreateItem represents a mail item in Outlook’s object model. The vbCrLf constants insert line breaks in the body. The error handler gives a message if Outlook cannot be started or the item cannot be created; it does not guarantee that the email was delivered.

Before running any macro, save a copy of the workbook. VBA actions cannot be undone with Ctrl+Z, and sending an email is an external action that cannot be recalled reliably. Run the macro from the Visual Basic Editor with F5, or return to Excel and run it from Developer > Macros.

Display first or send automatically?

.Display opens the message window so a person can check the recipient, subject, body, and attachments before clicking Send. It is the safer default while developing a macro, testing workbook values, or sending messages that need individual review.

To have Outlook send the message without opening the compose window, replace .Display with .Send. The macro then attempts to submit the message using the active Outlook profile. That does not mean the recipient has received or read it: delivery can still be delayed, rejected, filtered as junk, or blocked by account policy. Test with an address you control before automating real mail.

Outlook may use its default sending account. If a profile contains several accounts, do not assume that the account you want will always be selected. Account selection is possible through the Outlook object model, but it requires identifying the appropriate account and testing that behavior in the actual profile. Organizational settings can also affect which account is allowed to send.

Personalizing messages and adding attachments

A common next step is to fill in the message from worksheet cells. For example, a macro could read a recipient from one cell and a report period from another, then build a subject from those values. Check that cells are not blank and that addresses are valid before creating the mail item. A typo in a recipient cell can send confidential information to the wrong person if the macro uses .Send.

To make a message use basic HTML formatting, set HTMLBody instead of Body. HTML messages can include paragraphs, links, and simple formatting, but the string must contain valid HTML. Plain text is often more predictable for short notices and is easier to inspect when debugging. Do not paste untrusted worksheet content into HTML without considering how special characters and markup will be interpreted.

Outlook can attach a file through the mail item’s Attachments collection. The file must exist at the path supplied to the macro, and the Outlook account must be permitted to send it. Confirm the attachment is the intended, current file and that it is appropriate to share. A workbook path can change when files move between computers, so avoid assuming that a hard-coded path will work for every user.

If sending the same notice to several people, consider whether each recipient should see the others’ addresses. Use separate messages or the BCC field when appropriate, rather than placing a private distribution list in the visible To field. For a workbook-driven process, validate the recipient list and test with a small, internal group before sending at scale.

Common problems and practical checks

  • Outlook cannot be created: Confirm that classic Outlook is installed and that an account has been set up. The code will not work by switching to new Outlook.
  • The macro is blocked: Excel’s macro security settings or organizational policy may prevent it from running. Only enable macros in workbooks you trust; do not lower security globally just to run an unknown file.
  • The message opens but does not send: Check the Outlook Outbox, connection status, account configuration, and any error shown by Outlook. A successful call to .Send is not proof of delivery.
  • A security warning appears: Outlook’s programmatic-access protections can depend on the antivirus status and administrator policy. Do not try to bypass a company’s security controls; ask the administrator about an approved automation method.
  • The wrong text or recipient appears: Inspect the worksheet values and the macro’s assignments. Test with .Display first, and check for blank cells, extra spaces, misspelled addresses, or unexpected line breaks.
  • An attachment is missing: Verify the complete file path and that the file is available to the computer running Excel. A file stored on a disconnected network drive may not be accessible.

For troubleshooting, temporarily keep .Display in the code and inspect the message before sending. You can also add a breakpoint in the VBA editor by clicking beside a line of code, then step through the macro to see which values it uses. Avoid testing by sending repeatedly to a real mailing list.

Safety, privacy, and responsible use

Automated email can expose information quickly, so treat the macro as an action with real consequences, not just a formatting shortcut. Review the destination addresses, message content, and attachments. If a workbook contains customer, employee, financial, or other sensitive information, follow your organization’s data-handling rules and use only an approved account and process.

Do not use a macro to send unsolicited bulk messages or to evade mail-system controls. Organizations may restrict automated sending, impose message limits, or require an approved service. For recurring business notifications, involve the IT team before relying on a desktop Outlook profile, especially if the workbook must run unattended or from a shared computer.

Keep macros understandable and maintainable. A clear confirmation step, a small test list, and a log of what the macro attempted can reduce accidental sends. A log should record only information that is appropriate to retain; avoid storing unnecessary message contents or sensitive data.

When another method is a better fit

VBA with classic Outlook is a practical choice for a person who runs a workbook manually and wants Outlook to prepare or send a small number of messages. It is not always the right tool for unattended, high-volume, or cross-platform automation. The method depends on Windows desktop software, a configured Outlook profile, and local macro permissions.

For Microsoft 365 workflows that need to run without a user’s desktop session, an organization may approve Power Automate or another managed service. For application-level integrations, Microsoft Graph can provide a supported API-based approach, subject to the required identity, permissions, and administrator approval. These alternatives have their own setup and security requirements; they are not simply drop-in replacements for a short Excel macro.

Frequently Asked Questions

Can Excel VBA send an email without opening Outlook?

This Outlook Object Model method requires classic Outlook to be available, although .Send can submit a message without displaying its compose window. It is not a direct, Outlook-free sending method. Other approaches, such as an approved API or workflow service, have different configuration and permission requirements.

Why does my VBA email macro not work with new Outlook?

The example uses Windows COM automation and the classic Outlook Object Model. New Outlook does not support that traditional automation interface, so code that calls CreateObject("Outlook.Application") is not a compatible solution there. Use classic Outlook or choose a different approved automation method.

How do I send an email from Excel VBA without a security warning?

There is no universal VBA setting that safely removes Outlook’s programmatic-access protections. Warnings and restrictions can depend on Outlook, antivirus status, and administrator policy. Ask your IT administrator about the approved configuration rather than attempting to bypass a security control.

Can a macro attach a file to an Outlook email?

Yes. A mail item can add a file through its Attachments collection, provided the file path is correct and accessible. Check that the intended file is attached before sending, especially when the path is built from worksheet data or changes between computers.

Can I use this code in Excel for Mac or Excel for the web?

No. Excel for the web does not run VBA, and the Windows COM calls in this example are not supported by Outlook for Mac. A Mac user or web-based workflow needs a different approach designed for that platform.

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.