Yes, you can automate sending Excel data via email using a macro—without needing advanced coding knowledge—by leveraging VBA’s built-in Outlook.Application object. This method works for static data, dynamic ranges, or even formatted tables, but it requires Outlook to be installed and configured on the same PC. Below is a foolproof guide covering setup, troubleshooting, and avoiding pitfalls.
What You'll Need
- Microsoft Excel 2013 or later (VBA enabled)
- Microsoft Outlook installed on the same computer (no cloud-only Outlook accounts)
- A predefined email template (optional but recommended for consistency)
- Basic familiarity with Excel’s ribbon interface (if not, pause here and enable macros in
File > Options > Trust Center > Macro Settings) - Permissions to send emails from the PC’s configured Outlook profile (admins may need to grant macro permissions)
Step-by-Step
-
Open your Excel workbook and press
Alt+F11to launch the VBA Editor. This will display the project explorer on the left. -
Insert a new module:
- Right-click in the Project Explorer window on
VBAProject (YourWorkbookName). - Select Insert > Module. A blank code window will open.
- Right-click in the Project Explorer window on
-
Paste this basic macro template (adjust range and email details below):
Sub SendEmailWithExcelData() Dim OutlookApp As Object Dim OutlookMail As Object Dim ws As Worksheet 'Set the worksheet containing your data Set ws = ThisWorkbook.Sheets("Sheet1") 'Change to your sheet name 'Check if Outlook is installed On Error Resume Next Set OutlookApp = GetObject(, "Outlook.Application") If Err.Number <> 0 Then MsgBox "Outlook is not installed or not available.", vbCritical Exit Sub End If On Error GoTo 0 'Create a new email Set OutlookMail = OutlookApp.CreateItem(0) '0 = mail 'Configure email subject and body With OutlookMail .Subject = "Automated Excel Report: " & Format(Now(), "mm/dd/yyyy") .To = "recipient@example.com" 'Replace with recipient email .Body = "Please find the attached report below." & vbNewLine & vbNewLine & _ "Data Summary:" & vbNewLine & _ ws.Range("A1").CurrentRegion 'Displays table header + data 'Attach the entire sheet or selected range '.Attachments.Add ws.Path & "\" & ws.Name & ".xlsx" 'Uncomment for full workbook attachment '.Attachments.Add ws.Range("A1:D100").SpecialCells(xlCellTypeConstants).Address & ".xlsx" 'Uncomment for range export 'Set attachment to just the used range (preferred for small datasets) Dim attachmentPath As String attachmentPath = ThisWorkbook.Path & "\Temp_Report.xlsx" ws.Copy ActiveWorkbook.SaveAs attachmentPath, FileFormat:=xlOpenXMLWorkbook .Attachments.Add attachmentPath ActiveWorkbook.Close SaveChanges:=False End With -
Customize the macro:
- Replace
"Sheet1"with your worksheet name (verify via the worksheet tab). - Update the
.Toemail address(es) with semicolons for multiple recipients:"recipient1@example.com;recipient2@example.com". - Modify the subject line (e.g., to include a report name or date).
- For large datasets, uncomment the attachment lines to export only the used range (lines 22–23) or the entire workbook (line 20).
- Replace
- In the VBA Editor, click the Run button (green arrow) or press
F5. - If prompted by Outlook’s security warning, click Yes to enable macros.
- Check your Outlook Drafts folder to verify the email was created without errors.
- Send a test email to yourself to confirm formatting and attachments.
- Return to Excel and go to the Developer tab (enable it via
File > Options > Customize Ribbonif missing). - Click Insert > Button and choose Assign Macro.
- Select your macro from the list and click OK.
- Drag the button to your Quick Access Toolbar or worksheet for one-click access.
Common Mistakes
- Forgetting to check Outlook’s availability: The macro will fail silently if Outlook isn’t installed or is closed. Always include the error-handling code (lines 8–12) to alert users.
-
Incorrect worksheet or range references: Typos in sheet names (e.g.,
"Sheet1"vs."Sheet") or ranges (e.g.,"A1:C10"vs."A1:C100") will cause the macro to error. Usews.Range("A1").CurrentRegionto dynamically capture all data. -
Attachment path errors: If the macro tries to save a file to a non-existent path (e.g.,
"C:\Temp"), it will crash. Always useThisWorkbook.Pathto ensure the file is saved in the same directory as the workbook. -
Ignoring Outlook’s macro security settings: Modern Outlook versions may block macros by default. Users must enable them via
File > Options > Trust Center > Trust Center Settings > Macro Settingsand select Enable all macros (not recommended for security-sensitive environments). - Not testing with sample data: A macro that works with hardcoded values may fail when the worksheet updates. Always test with real data, especially if formulas or dynamic ranges are involved.
Tips
- Use a template email: For consistency, save a pre-formatted email as a template (in Outlook’s New Items > Choose Form > User Templates) and modify the macro to open it instead of creating a new email.
-
Add error handling for email failures: Extend the macro to check if the email was sent successfully. Example:
On Error Resume Next .Send 'Attempt to send If Err.Number <> 0 Then MsgBox "Failed to send email. Error: " & Err.Description, vbCritical End If On Error GoTo 0 -
Schedule the macro to run automatically: Use Excel’s VBA Editor > Alt+F8 > Macros > Options to set a shortcut key or assign it to a worksheet event (e.g.,
Worksheet_Change) for triggers like data entry. -
Clean up temporary files: The macro creates a temporary Excel file. Add this after sending to delete it:
Kill attachmentPath -
Document your macro: Add comments in the VBA code (e.g.,
'Change "recipient@example.com" to actual email) so others (or your future self) can update it easily.
Troubleshooting
If the macro runs but no email appears:
-
Check Outlook’s Send/Receive settings:
- Open Outlook and go to Send/Receive > Send/Receive Groups > Define Send/Receive Groups.
- Ensure the default group is set to All Accounts or Online.
- Click Send/Receive > Send/Receive Now to force a sync.
-
Verify the email account is configured correctly:
- In Outlook, go to File > Info > Account Settings.
- Check that the account is enabled and has a valid SMTP server.
- If using an exchange account, ensure offline mode is disabled (File > Info > Work Offline).
-
Test with a simple email first:
Set OutlookMail = OutlookApp.CreateItem(0) With OutlookMail .Subject = "Test Email" .Body = "This is a test." .Send 'Use .Display to preview instead of sending End WithIf this works, the issue is likely in your data or attachment code.
If you get "Object Required" errors:
- Ensure you’ve declared all objects with
Dim(e.g.,Dim OutlookMail As Object). - Check for missing periods (.) in method calls (e.g.,
OutlookMail.Sendinstead ofOutlookMail.Send()). - Restart Excel and Outlook to clear any corrupted references.
If the attachment is corrupted:
- Replace the attachment code with:
Dim attachmentPath As String attachmentPath = ThisWorkbook.Path & "\Report_" & Format(Now(), "yyyy_mm_dd") & ".xlsx" ThisWorkbook.Copy ActiveWorkbook.SaveAs attachmentPath, FileFormat:=xlOpenXMLWorkbook OutlookMail.Attachments.Add attachmentPath ActiveWorkbook.Close SaveChanges:=False - Ensure the folder where the file is saved has write permissions.
If Outlook blocks the macro:
- Open Outlook and go to File > Options > Trust Center > Trust Center Settings > Macro Settings.
- Select Enable all macros (temporarily for testing).
- If security is a concern, use a Trust Centered approach by adding your workbook’s location to the trusted folder list.
Frequently Asked Questions
Can I send the email without Outlook installed?
No. The VBA method requires Outlook to be installed and configured on the same PC. Alternatives include using Excel’s Application.SendKeys to trigger an email client (risky and unreliable) or third-party add-ins like Redemption (commercial). For cloud-based solutions, consider Power Automate or Google Apps Script.
Will this work if the recipient’s email is in a different format (e.g., with a name like "John Doe <john@example.com>")?
Yes, but the macro must include the full email address. Outlook’s .To field only accepts valid email addresses. If you need to use display names, combine them like this:
.To = "John Doe"
Can I send the email as HTML or with formatting?
Yes. Modify the .Body to use HTML tags or add a formatted table:
.WithOutlookMail
.Subject = "HTML Report"
.HTMLBody = "Monthly Sales
.HTMLBody.
How do I send the email as a BCC?
Use the .BCC property:
.WithOutlookMail
.Subject = "BCC Report"
.To = "manager@example.com" 'Primary recipient
.BCC = "audit@example.com" 'Hidden recipient
.Send
End With
Note: BCC recipients must be added via the .BCC property, not the .To field.
Will this work on a macro-enabled workbook shared with others?
No. Macros require the workbook to be opened with Enable Content in Excel’s security prompt. To share securely:
- Save the macro code in a separate workbook (e.g.,
MacrosOnly.xlsm). - Use
Application.Runto call the macro from the shared workbook:Application.Run "MacrosOnly.xlsm!SendEmailWithExcelData" - Distribute the shared workbook as
.xlsx(disable macros) and the macro workbook as.xlsm(require users to enable macros).
Can I schedule this macro to run daily?
Yes, but Excel’s VBA cannot natively schedule tasks. Use one of these methods:
-
Windows Task Scheduler:
- Open
Task Scheduler(search in Start Menu). - Create a Basic Task to launch Excel with your workbook and press the macro’s shortcut key.
- Set the trigger to "Daily" at your preferred time.
- Open
-
Excel’s built-in timer (less reliable):
Use a worksheet event like
Workbook_Opento trigger the macro after a delay (requiresApplication.OnTime).
What if the recipient’s email domain blocks automated messages?
Many corporate domains (e.g., Gmail, Outlook.com) flag automated emails as spam. To improve deliverability:
- Use a real, monitored email account (e.g., your work account) as the sender.
- Add a custom header to mimic a human sender (advanced; requires
OutlookRedemptionorCDOlibraries).Dim objCDOMessage As Object Set objCDOMessage = CreateObject("CDO.Message") objCDOMessage.From = "Your Name" objCDOMessage.To = "recipient@example.com" '... - Send a test email first to confirm the domain allows it.