Excel Macro to Send Email: Setup, Code, and Safety

VBA & macros · Updated November 3, 2026

Excel Macro to Send Email: Setup, Code, and Safety

Yes. In Excel for Microsoft 365 on Windows, a VBA macro can create an email in classic Outlook using details from worksheet cells. The example below opens a draft for review; you can change it to send automatically, but check recipients and content carefully first. This method requires desktop Excel and classic Outlook, not Excel for the web or the new Outlook for Windows.

What an Excel email macro does

An email macro reads information from a workbook and passes it to an email program. A simple version might take a name and email address from a row, put them into the recipient and message fields, and display the draft. A more developed one could create a separate message for each row, add a subject based on a cell, or attach a file. The spreadsheet supplies the data; Outlook handles the email message and delivery.

This is useful when a message follows a repeatable pattern, such as sending a report to a colleague or preparing individual notices from a contact list. It does not make Excel an email server, and it does not bypass Outlook’s account setup, organizational rules, or security controls. In the example here, the macro asks Outlook to show a draft, so you can inspect it and click Send yourself.

Requirements and Outlook compatibility

The VBA example is for the Windows desktop versions of Excel and classic Outlook for Windows. Classic Outlook must be installed and configured with an account that can send mail. Excel communicates with it through Windows automation, often called COM automation. The sample uses late binding, which means you do not need to add an Outlook reference in the VBA editor.

The new Outlook for Windows does not provide the classic Outlook COM automation interface used by this approach. If your computer has only the new Outlook, this macro may fail to create a message. Excel for the web cannot run VBA macros at all. On a Mac, Excel supports VBA, but this Windows COM method is not a cross-platform way to automate Outlook; use a Mac-specific workflow or an alternative such as Power Automate.

To keep VBA in the workbook, save it as an Excel Macro-Enabled Workbook (*.xlsm). A macro-enabled file can contain code, so open files only when you trust their source and purpose.

Prepare the worksheet

For the example, use a worksheet named Sheet1 with the recipient’s name in A2 and email address in B2. For instance, A2 could contain Jordan Lee and B2 could contain jordan@example.com. The macro reads just that row; it does not send to a whole list.

  • Put a valid email address in B2 and a name in A2. The code checks that neither value is blank, but it does not verify that the address exists.
  • Change the worksheet name in the code if your sheet is not called Sheet1. Worksheet names must match, including spaces.
  • Save the workbook as an .xlsm file before adding or running the code.

For real contact data, avoid putting confidential information in a workbook that will be shared broadly. A typo in a recipient cell can disclose a message to the wrong person, and a macro cannot reliably determine whether an address belongs to the intended recipient.

Add and run the VBA macro

In Windows Excel, press Alt+F11 to open the Visual Basic Editor, then choose Insert > Module. Paste the code below into the module, return to Excel, and press Alt+F8. Select DraftEmail and choose Run. The first run should open an Outlook draft, not send it. Save a separate copy of the workbook before running any macro: VBA changes and email actions cannot be undone with Ctrl+Z.

Sub DraftEmail()
    Dim ws As Worksheet
    Dim outlookApp As Object
    Dim mail As Object
    Dim recipient As String
    Dim displayName As String

    On Error GoTo Failed

    ' Read the recipient details from the example worksheet.
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    displayName = Trim(CStr(ws.Range("A2").Value))
    recipient = Trim(CStr(ws.Range("B2").Value))

    ' Stop rather than create a draft with missing details.
    If displayName = "" Or recipient = "" Then
        MsgBox "Enter a name in A2 and an email address in B2."
        Exit Sub
    End If

    ' Start or connect to classic Outlook and create a message.
    Set outlookApp = CreateObject("Outlook.Application")
    Set mail = outlookApp.CreateItem(0)
    With mail
        .To = recipient
        .Subject = "A message from Excel"
        .Body = "Hello " & displayName & "," & vbCrLf & vbCrLf & _
                "Here is the information we discussed." & vbCrLf & vbCrLf & _
                "Regards," & vbCrLf & "Your name"
        .Display ' Review the draft before sending.
    End With

    Set mail = Nothing
    Set outlookApp = Nothing
    Exit Sub

Failed:
    MsgBox "The email draft could not be created: " & Err.Description
End Sub

The ampersands shown as & in the HTML code block represent the VBA concatenation operator, &. When you paste the code into the Visual Basic Editor, use the ordinary ampersand character (&), not the text “&”. The code uses .Display so Outlook opens the message for inspection. If you intentionally want the macro to send without showing the draft, replace .Display with .Send; test with your own address first and understand that this removes the review step.

Customize the message and data

Change the .Subject and .Body lines to set the text you need. In VBA, vbCrLf inserts a new line in a plain-text message, and the ampersand joins pieces of text together. You can read a different cell by changing a reference such as ws.Range(“A2”). For example, a subject stored in C2 could be assigned with .Subject = CStr(ws.Range(“C2”).Value). Ensure that the cell contains the subject you actually want before running the macro.

To include a value from a cell in the body, build the body from fixed text and the cell value. For example, if D2 contains a report total, concatenate its value into the message after checking that the cell is populated. If you need currency, dates, or leading zeroes to appear in a particular format, convert or format the value deliberately; VBA may otherwise use a representation that differs from the worksheet’s displayed format. Review the resulting draft to catch formatting surprises.

Outlook’s default signature may also affect what appears in a displayed message, depending on Outlook configuration and how the message body is populated. Inspect the draft rather than assuming the signature or body layout will be exactly as expected.

Sending messages to multiple rows

A contact-list macro usually loops through a range of rows, creating one message per row. Before building that version, decide what should happen with blank addresses, duplicate contacts, invalid-looking entries, and rows that have already been processed. A safe design can mark each row as pending, display drafts for review, and record a status only after the message has been handled. Sending every row automatically is risky if a filter, sort, or accidental selection leaves unexpected data in the range.

For example, a list might keep names in column A, addresses in B, and a personalized note in C. The macro can read each row and place the note in that recipient’s message. It should still validate required cells and avoid placing every recipient in the To field: separate messages protect recipients’ privacy and allow personalization. For a first test, use a copy of the workbook with a few rows and your own email address, and keep the code on .Display until the workflow is confirmed.

Large or repeated sends may also be subject to Outlook, Microsoft 365, or organization sending limits and anti-spam policies. A macro does not increase those limits. For scheduled or business-critical campaigns, use an approved mailing or workflow service and check its current rules with your administrator.

Security, privacy, and macro settings

Excel may block macros from an untrusted file, and an organization may control which macros can run. On Windows, macro options are under File > Options > Trust Center > Trust Center Settings > Macro Settings. Do not enable all macros just to run one workbook. Follow your organization’s policy; for a recurring internal tool, ask whether a digitally signed macro or an approved trusted location is appropriate.

Be especially cautious with automatic sending. A wrong range, stale address, hidden row, or unintended cell value can turn a useful automation into a privacy incident. Use a preview stage, test with non-sensitive sample data, and keep the recipient list limited to people who should receive the content. Avoid attaching a workbook automatically until you have checked that it contains no hidden sheets, comments, or other information that should not be shared.

Save a backup before testing. Macros can edit cells, create messages, or send email, and Ctrl+Z does not reverse those actions. If a draft is wrong, close it without sending and correct the workbook or code before trying again.

Common problems and how to diagnose them

  • “The email draft could not be created” or an automation error: Confirm that classic Outlook is installed and configured, and that the workbook is running in desktop Excel on Windows. The new Outlook and Excel for the web do not support this sample’s automation method.
  • Subscript out of range: The worksheet name in Worksheets(“Sheet1”) does not match a tab in the workbook. Change the code to the exact sheet name.
  • The macro does not appear in Alt+F8: Confirm that the code is in a standard module, the file is saved as .xlsm, and macros are permitted under your organization’s settings.
  • The draft has no recipient or name: Check A2 and B2, including whether the data is on the expected sheet. The example trims surrounding spaces but cannot confirm that an address is deliverable.
  • Outlook shows a warning or blocks an action: Security behavior can depend on Outlook version, antivirus status, and administrator policy. Do not try to defeat the warning; ask your IT administrator about an approved method.

If an error appears, note the exact message and the line highlighted in the Visual Basic Editor. That usually narrows the cause to a missing sheet, unavailable Outlook automation, or an issue creating the message. Avoid changing macro security settings broadly as a troubleshooting shortcut.

Alternatives to VBA email automation

If you only need to send one message, composing it directly in Outlook and copying the relevant spreadsheet values may be simpler and safer. If you want a repeatable process without desktop VBA, Power Automate can use a flow to send an email from a supported Microsoft 365 connection. The exact trigger, available connectors, licensing, and organizational permissions depend on the account and setup, so confirm them before designing a workflow.

Office Scripts can automate supported tasks in Excel for the web, but an Office Script by itself is not a replacement for the Outlook COM calls in this example. A flow can coordinate an Office Script with other actions where supported. For Mac users, a Mac-compatible automation approach is needed; do not expect the Windows Outlook.Application code to work unchanged. Choose based on where the workbook runs, who maintains the process, whether a person must approve each message, and how sensitive the data is.

Frequently Asked Questions

Can Excel send an email automatically when a cell changes?
VBA can respond to worksheet events, but automatic sending on a cell change can produce unintended messages and still requires compatible desktop software and Outlook. A safer approach is to flag eligible rows and use a deliberate button or review step. For unattended workflows, consider an approved Power Automate flow with appropriate safeguards.

Can I use this macro with the new Outlook?
No, this example relies on classic Outlook’s Windows COM automation interface. The new Outlook for Windows does not support that interface. Use a supported alternative such as Power Automate, subject to your account and organization’s setup.

Will the macro send if Outlook is closed?
The code asks Windows to create an Outlook.Application object. Whether Outlook can start and create a message depends on the installed classic Outlook configuration and account setup. It is not a guarantee of unattended delivery; test the actual computer and account, and inspect the draft.

Can Excel for the web run a VBA email macro?
No. Excel for the web does not run VBA. Open the macro-enabled workbook in desktop Excel on a compatible Windows setup, or use a different workflow designed for web-based automation.

Can the macro attach a file?
Classic Outlook VBA can add an attachment, but the path must exist and the file must be the intended one. If adding that feature, validate the path, preview the message, and check the attachment before sending; a mistaken attachment can expose information even when the message text is correct.

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.