How to Email Each Excel Worksheet as a PDF Attachment Using VBA
Question details
The user needs to export multiple individual worksheets as PDFs and automatically email them to specific addresses stored in a designated cell on each sheet.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Distributing personalized information (such as employee records) stored on separate worksheets to individual recipients via an automated email process.
- Observed behavior
- A VBA macro is required to loop through sheets, save them as PDFs, read the email address from a specific cell (e.g., K1), attach the PDF to an Outlook email, send it, and clean up temporary files.
Ensure Microsoft Outlook is installed, set as your default email client, and properly configured with your active email account before executing the macro. Save a backup of your workbook before running any new VBA code.
Use VBA to Export Worksheets as PDFs and Automate Outlook Emails
Create a macro that iterates through each worksheet, uses the ExportAsFixedFormat method to generate a temporary PDF, and attaches it to a new Outlook email.
By utilizing Excel's built-in PDF export feature alongside Outlook's COM object library, you can automate the entire process of generating and sending reports. The macro will dynamically read the recipient's address from cell K1 on each active worksheet.
Press Alt + F11 in your Excel workbook to launch the Visual Basic for Applications (VBA) editor. Click 'Insert' in the top menu and select 'Module' to create a blank workspace for your code.
Declare variables for the Worksheet, Outlook Application, and Mail Item. Set up a 'For Each ws In ThisWorkbook.Worksheets' loop so the code processes every tab in your workbook individually.
Define a temporary file path string on your local drive (e.g., your Temp folder). Use the command 'ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=tempFilePath' to save the current sheet.
Initialize Outlook using 'CreateObject("Outlook.Application")'. Generate a new mail item, assign 'ws.Range("K1").Value' to the '.To' field, and use '.Attachments.Add tempFilePath' to attach your newly created PDF.
After the '.Send' command, add the 'Kill tempFilePath' statement. This ensures the temporary PDF file is deleted from your hard drive before the loop moves to the next employee's worksheet.

A Better Way to Manage Spreadsheets and PDFs
If you are experiencing issues with complex VBA macros and Outlook integration, consider switching to WPS Office. It provides a highly compatible, easy-to-use alternative to Microsoft Excel, featuring powerful built-in PDF conversion tools without the need for complex coding.
- 1. Download and Install: Visit the official WPS website to download the free installation package for your operating system.
- 2. Open Your Spreadsheet: Launch WPS Spreadsheet and easily open your existing Excel workbooks with full formatting preservation.
- 3. Use Built-in PDF Tools: Navigate to the 'Tools' tab to access native 'Export to PDF' functionalities, allowing you to bypass complicated macro setups for standard reporting.

Frequently Asked Questions
Why does my macro crash when trying to create an Outlook email?
This typically happens if Microsoft Outlook is not installed locally, not set as your system's default mail client, or if the Outlook application is hanging in the background. Ensure Outlook is open and functioning normally before executing the macro.
Can I specify a different cell for the recipient's email address?
Yes. In your VBA code, locate the reference to ws.Range("K1").Value and update it to match the exact cell reference (such as "B5" or "Z10") that contains the email address in your specific worksheet layout.
How can I customize the file name of the generated PDF?
You can dynamically generate the file name by customizing the tempFilePath variable in your code. For example, you can concatenate the path with an employee's name found in cell A1 by using: tempFilePath = "C:\Temp\" & ws.Range("A1").Value & ".pdf".




