Send emails from Excel with attachments using Power Automate

Get the Power Automate Starter Kit

A free 2-page guide with four flows to build next: save email attachments to OneDrive, send Forms answers to Excel, approve files and get a Monday list of overdue items. Plus a fix-it checklist and 4 expressions worth keeping.

Set Up the Excel Table and PDF Files

Located in our OneDrive is a folder called “Contracts” that holds a series of uniquely crafted PDF files along with an Excel file.

OneDrive Contracts folder with PDF contracts and the FilesMaster Excel file

The Excel file has a table named “TableFiles” that holds information about the user’s name, email address, and name of the PDF file for that user.

Excel table TableFiles with first name, last name, email and file name columns

The PDF files are contracts with information specific to each recipient’s negotiated details.

Personalized PDF membership contract for one recipient

These files can be stored in OneDrive, SharePoint, or a different folder from the one holding the Excel file.

Prefer to skip Power Automate? You can also email Excel sheets as PDF with Office Scripts.

Our goal is to select the PDF files in the Excel document and then run a Power Automate Flow to perform all the merging and distribution of the data to the users.

Create an Instant Cloud Flow

Go to make.powerautomate.com and sign in with your work or school Microsoft 365 account.

Power Automate in the Microsoft 365 app launcher

Since we are creating a Flow from scratch, we select “Create” from the list of Power Automate categories on the left of the screen.

Create option in the Power Automate menu

Flows start by defining the “trigger”; what is going to cause this Flow to execute its instructions.

Because our Flow is triggered based on cells selected in an Excel file, this falls under the purview of an Instant Cloud Flow.

Instant cloud flow option in Power Automate

Give the Flow a name, such as “Mail Merge with Attachment”.

Naming the new instant cloud flow

Scroll down the list of triggers and select For a selected row (Excel Online (Business)).

For a selected row trigger for Excel Online (Business)

Click “Create” to move to the next steps.

Connect the Flow to Your Excel Table

The next step is to tell the Flow where the Excel file is located and which table in the Excel file to consult when performing the email distribution.

Trigger settings with OneDrive for Business, the FilesMaster file and TableFiles

Click New step to add the next action. In the new designer, click the + sign instead.

List the Files in the PDF Folder

We need our Flow to check the filename listed in the Excel table to see if there is a PDF in a folder that matches the filename.  If so, we want to attach that folder’s file to the outgoing email message.

File names in the Excel table matching the PDF names in the folder

We want to loop through all files in a folder, checking for a matching name.

This is an action supported by OneDrive.

Search for OneDrive and select OneDrive for Business.

Searching for OneDrive in Power Automate actions

In the list of Actions, scroll down to locate “List Files in Folder”.

List files in folder action for OneDrive for Business

Click the Browse button to locate the folder holding the PDF files.

Selecting the Contracts folder in List files in folder

Click New step (or the + sign) to set up the loop.

Loop Through the Files and Match the Names

In the “Choose an Operation” panel, select “Control”.

Control connector in Power Automate

Select the control labeled “Apply to Each”.

Apply to each control

We need to use an output from the previous step.  Scrolling down the list of Dynamic Content, we select “Value” from the list.

Value from dynamic content selected for Apply to each

Next, click “Add an Action” to add another “Control”.  This time we will use a “Condition”.

Condition control in Power Automate

This allows checking to see if something occurs based on some form of logic and then act in one of two fashions.  This is like writing an IF statement in Excel except it will be created using all point-and-click actions.

Our objective is to cross-check the name of the PDF file against the current row’s defined filename.

We need to point to the column in the Excel file labeled “File Name”.

File Name column in the Excel table

Scrolling down the list of Dynamic Content, we come across an entry for the “File Name” field from the Excel file’s table.

File Name dynamic content from the Excel trigger

Set the operator to is equal to and pick Display Name on the right. Display Name is the file name with its extension, so it matches how the names are written in the Excel table.

Condition checking that File Name is equal to Display Name

Get the Matching File’s Content

To define what happens if one of the PDF file’s display names matches the listed filename in the Excel cell, click the “Add an Action” located in the “If Yes” panel.

Add an action in the If yes branch

Like we did previously, in the “Choose an Operation” panel, search for “OneDrive” and select “OneDrive for Business”.

OneDrive for Business connector in the If yes branch

Scroll down the list of Actions to locate the “Get File Content” action.

Get file content action in OneDrive for Business

In the “Get File Content” panel, scroll down the list of Dynamic Content and select “Id”.

Id dynamic content selected in Get file content

Tip: if your file names always match exactly, you can skip the loop. Use the OneDrive action Get file content using path, with the folder path plus the File Name column from Excel.

Click “Add an Action” to begin setting up the email operation.

Build the Personalized Email

Search for “Outlook” to locate all Outlook-related operations.

Searching for Outlook actions in Power Automate

Select the Action labeled “Send an Email (v2)”.

Send an email (V2) action in Office 365 Outlook

Set the To Field

We need the TO: field to be dynamic based on the “Email” column in the Excel table.

Email column in the Excel table

Click “Add Dynamic Content” and scroll down to select “Email” from the list.

Email dynamic content in the To field

Write the Subject

The subject can be a fixed statement for all email recipients, or it can be dynamically customized for each recipient.  Making it dynamic would require an additional column in the table to hold all the unique subject lines.

For this example, we will go with the fixed statement “Your Contract”.

Write the Email Body

For the body, mix fixed text with dynamic content. For example: Hi [First Name], please find attached your file: [Name without extension]. Best regards. Each person sees their own name and file name.

The result of the To:, Subject:, and Body: elements appears as follows.

Send an email action with To, Subject and Body filled in

The only thing missing is the actual PDF attachment for each outgoing email message.

Attach the PDF

In the Send an email (V2) action, click Show advanced options. In the new designer, select Show all next to Advanced parameters.

Show advanced options in Send an email

The Advanced Options allows you to exercise several email-related actions, such as:

  • Defining a sender’s email address
  • Add CC or BCC email addresses
  • Attach files
  • Redirect replies to an alternate email address
  • Set Importance levels

All of which can be defined dynamically.

To attach a PDF file:

  1. Set the “Attachment Name” option to the “Name” field in the Dynamic Content list
  2. Set the “Attachment Content” option to the “File Content” field in the Dynamic Content list
Attachment name and content set from dynamic content

Click the Save button (upper-right) to save the Flow to our Power Automate library.

Power Automate message saying the flow is ready

Run the Flow from Excel

Open the Excel file in Excel for the web. If it’s also open in the desktop app, close that copy first so two versions aren’t editing the same file.

FilesMaster Excel file in OneDrive

To execute the Flow, select the Data tab and click Flow from the Automation group.

Flow button on the Data tab in Excel for the web

NOTE: If you don’t see the Flow button, go to Add-ins and install Microsoft Power Automate for Excel. In newer versions it appears as Automate Work on the Automate tab.

Want more ways to start flows from a workbook? Here’s how to use Power Automate in Excel.

Office Add-ins dialog with the Microsoft Flow add-in

Once you have activated Flow the following panel appears to the right of the Excel window listing all of the Power Automate Flows that are compatible with Excel.

Flow panel listing the flows for this Excel file

If you select a single “File Name” cell in the table, the Flow will only process that single row’s PDF comparison and deliver a single email message.

If you select all the rows in the table (you can get away with only selecting the column of PDF filenames), the Flow will process all selected rows.

With the cell(s) selected, click the “Run” arrow.

Run arrow next to the flow in the Excel panel

If this is the first time you have used the Flow, you may need to sign in to your OneDrive account.

Sign-in prompt for the flow connections

Click the “Run Flow” to execute the Flow process.

Run flow button in the Excel flow panel

You can monitor the execution and completion status of the Flow by visiting the Flow Runs Page or click Done to exit the Flow panel.

Message confirming the flow run started

Check the Results

The received email will appear as follows with the included attachment.

Received email with the personal PDF contract attached

Opening the attached PDF, we see that it is the PDF file that was designated for the intended recipient.

Opened PDF contract for the right recipient

Get the Power Automate Starter Kit

Download the Power Automate Starter Kit

One flow step by step, three more to try and a fix-it checklist.

Frequently Asked Questions

Can I send emails with different attachments from Excel without VBA?

Yes. Keep the names, email addresses and file names in an Excel table, and let a Power Automate flow match each row to its PDF and send it. You run the flow from Excel with no macros or paid add-ins.

Do I need a work or school account for this flow?

Yes. The For a selected row trigger belongs to the Excel Online (Business) connector, which works with files in OneDrive for Business and SharePoint. A personal Microsoft account will not connect.

Why does my flow not find the PDF file?

The file name in the Excel table must match the Display Name exactly, including the .pdf extension. Check spelling and extra spaces, and make sure List files in folder points to the right folder.

How do I send emails to several people at once?

Select several rows in the Excel table, or several cells in the File Name column, before you click Run flow. The flow runs once for each selected row.

Can I attach more than one file to each email?

Yes. In the Attachments section of Send an email (V2), add another item and set its name and content. You can also add CC addresses or change the Reply To address in the same section.

Do the PDF files have to be in the same folder as the Excel file?

No. They can sit in any OneDrive folder or in SharePoint. Point the List files in folder action at the folder that holds the PDFs.

Leila Gharani

Founder of XelPlus and ten-time Microsoft MVP. Leila helps over 500,000 professionals master Excel, Power BI, and data automation through practical, real-world training.