This guide shows how to build an Excel macro that automatically generates a new email in Outlook using data from an Excel worksheet. It works by automating Outlook via VBA, creating a draft email with specified recipients, subject, and body—ready for you to review or send. You must have Microsoft Excel and Outlook installed on the same Windows machine, with Outlook configured to run as the default email client. The macro does not send emails automatically (to avoid accidental sends), but opens them in Outlook for final approval.
What You'll Need
- Microsoft Excel (2016, 2019, 2021, or Microsoft 365)
- Microsoft Outlook installed and set as the default email program
- A Windows PC (macOS does not support Outlook VBA automation in the same way)
- Basic familiarity with Excel and VBA (macros)
- A worksheet with email data (e.g., column A: recipient email, B: subject, C: body, D: CC, E: BCC)
Step-by-Step
- Open your Excel workbook containing the email data. Ensure your data starts in row 2 (row 1 is headers), and columns are labeled clearly (e.g., A = To, B = CC, C = BCC, D = Subject, E = Body).
- Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
- In the VBA editor, go to Tools > References. In the list, scroll down and check Microsoft Outlook xx.x Object Library (where xx.x is the version number, e.g., 16.0 for Microsoft 365). Click OK. This grants VBA access to Outlook’s object model.
- Go to Insert > Module to create a new blank code module.
- Copy and paste the following VBA code into the module. Replace the placeholder range references (e.g., "A2:E2") with the actual row you want to process, or modify the loop to handle multiple rows:
Sub CreateOutlookEmailFromExcel() Dim outlookApp As Outlook.Application Dim outlookMail As Outlook.MailItem Dim ws As Worksheet Dim lastRow As Long Dim i As Long ' Set the worksheet containing your data Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name ' Find the last row with data in column A lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row ' Create Outlook application object Set outlookApp = New Outlook.Application ' Loop through each data row (starting at row 2) For i = 2 To lastRow Set outlookMail = outlookApp.CreateItem(olMailItem) With outlookMail .To = ws.Cells(i, 1).Value .CC = ws.Cells(i, 2).Value .BCC = ws.Cells(i, 3).Value .Subject = ws.Cells(i, 4).Value .Body = ws.Cells(i, 5).Value .Display ' Use .Send to auto-send (NOT recommended for safety) End With Next i ' Clean up Set outlookMail = Nothing Set outlookApp = Nothing MsgBox "Email drafts created!", vbInformation End Sub - Close the VBA editor and return to Excel.
- Save your workbook as a Macro-Enabled Workbook (.xlsm) by clicking File > Save As, then selecting "Excel Macro-Enabled Workbook (*.xlsm)" from the file type dropdown.
- Press Alt + F8 to open the Macro dialog, select CreateOutlookEmailFromExcel, and click Run. Outlook will open (if not already running) and display a new draft email for each row in your data. You can edit or send them manually.
Common Mistakes
- Forgetting to set Outlook as the default email client—this causes automation to fail or open the wrong app.
- Missing the Outlook object library reference in step 3; without it, you’ll get a “User-defined type not defined” error.
- Using `.Send` instead of `.Display`—this sends emails immediately without review, risking accidental sends or spamming.
- Not handling empty cells: if a cell like CC or BCC is blank, Outlook may throw an error. Use `.To = IIf(Len(ws.Cells(i, 1).Value) > 0, ws.Cells(i, 1).Value, "")` to avoid this.
- Running the macro on a Mac: Outlook for Mac uses a different object model (not compatible with Windows VBA), so this method won’t work.
- Security prompts: Outlook may block automation. If you see a pop-up asking to allow access, click Allow (or for newer versions, adjust macro security in Excel under File > Options > Trust Center > Trust Center Settings > Macro Settings > enable macros temporarily).
Tips
- Use `.HTMLBody` instead of `.Body` if you want formatted text (e.g., bold, colors). Replace `.Body = ws.Cells(i, 5).Value` with `.HTMLBody = "" & ws.Cells(i, 5).Value & ""` and ensure your body data contains valid HTML.
- Add error handling: wrap your code in `On Error GoTo ErrorHandler` blocks to catch missing email addresses or Outlook issues without crashing Excel.
- Test on a small dataset first (e.g., just two rows) before running on your full list.
- Store sensitive data (like email bodies with confidential info) securely—don’t leave large volumes in Excel sheets unencrypted.
- For repeated use, assign the macro to a button: go to the Developer tab > Insert > Button (Form Control), draw it on your sheet, and assign the macro.
Troubleshooting
- Error: "ActiveX component can't create object" — Ensure Outlook is installed and the correct version of the Outlook Object Library is referenced. Restart Excel and try again. If Outlook is running in compatibility mode, disable that.
- Emails not appearing in Outlook — Check if Outlook is set as the default email program (Settings > Apps > Default Apps > Mail). If another app (e.g., Mail app) is default, change it.
- Macro not listed in Alt + F8 — Verify the macro is in a standard module (not ThisWorkbook or a sheet module). Also confirm the workbook is saved as .xlsm.
- Outlook security warning blocks the macro — Click "Allow" if the prompt appears. If it doesn’t appear and emails aren’t created, temporarily lower macro security (Trust Center settings) or use Click-to-Run fixes like the Outlook Security Patch bypass (only if your organization permits it).
- Run-time error '287': Application-defined or object-defined error — This usually means Outlook is blocking programmatic access. Try restarting Outlook, or check if antivirus/firewall is interfering. As a last resort, use Outlook’s built-in Quick Steps or Rules instead of macros for automation.