# Microsoft Quietly Added Email to Excel - Here's How to Use It

## Метаданные

- **Канал:** Leila Gharani
- **YouTube:** https://www.youtube.com/watch?v=RwcEa9fJsAk
- **Дата:** 14.05.2026
- **Длительность:** 13:04
- **Просмотры:** 33,645

## Описание

🔥 500,000+ enrolled in our courses. Join them 👉 https://link.xelplus.com/yt-d-all-courses
Stop wasting hours manually saving, naming, and emailing Excel reports! In this tutorial, we unlock the power of Office Scripts to automate your entire reporting workflow. You will learn how to build a 1-click button that converts specific sheets to PDF and sends them via Outlook instantly. All with the help of Office Scripts in Excel.

⬇️ DOWNLOAD the workbook with the code here: https://www.xelplus.com/office-scripts-pdf-email-excel/#download

Unlike traditional VBA macros, this solution is online-ready and works perfectly in Excel for the Web, Microsoft Teams and Microsoft 365 - and of course also on desktop. We’ll walk through the TypeScript code, set up a dynamic data table for your recipients, and show you how to customize the script for your own dashboards.

Microsoft Learn page: https://learn.microsoft.com/en-us/office/dev/scripts/resources/samples/save-as-pdf-email-as-pdf

What You'll Learn:
- How to use the convertToPdf and sendMail APIs in Office Scripts.
- Setting up a recipient table (Name, Email, Sheet Name) for bulk processing.
- Connecting a script to a "Run" button for a professional UI.
- Why Office Scripts are the modern, secure alternative to VBA for report distribution.

🕐 Timestamps
00:00 The Manual Reporting Problem (And the 1-Click Solution)
01:15 Setting Up Your Dashboard: The Data Table Structure
02:45 Introduction to Office Scripts & The Automate Tab
04:10 Script Walkthrough: Understanding convertToPdf & sendMail
06:30 Customizing the Code for Multiple Recipients
08:20 Adding the Automation Button to Your Sheet
09:50 Live Demo: Bulk Emailing PDF Reports
11:05 Troubleshooting & Common Script Errors
12:30 Final Tips: Moving from VBA to Office Scripts

📨 Subscribe to "Between the Sheets" newsletter to stay on top of office tips and Excel hacks: https://link.xelplus.com/yt-d-newsletter

🔓 Join this channel to get access to perks:
https://www.youtube.com/channel/UCJtUOos_MwJa_Ewii-R3cJA/join

🎬 LINKS to related videos:
Introduction to Office Scripts: https://youtu.be/fny4zUycp_w
Create Cool Buttons to Run Office Scripts from ANYWHERE: https://youtu.be/djf3tBIYmCw

👕 Get the Official XelPlus MERCH: https://xelplus.creator-spring.com/

🧭 Not sure which of my Excel courses fits best for you? Take the quiz: https://www.xelplus.com/course-quiz/

🧰 Resources I recommend: https://www.xelplus.com/resources/

🛒 More resources on my Amazon page: https://www.amazon.com/shop/leilagharani

📲 Let’s connect on social:
Instagram: https://www.instagram.com/lgharani
LinkedIn: https://www.linkedin.com/company/xelplus

This description contains affiliate links, which means at no additional cost to you, we will receive a small commission if you make a purchase using the links. This helps support the channel and allows us to continue to make videos like this. Thank you for your support!

#Excel #officescripts

## Содержание

### [0:00](https://www.youtube.com/watch?v=RwcEa9fJsAk) The Manual Reporting Problem (And the 1-Click Solution)

If you convert your Excel reports to PDFs and then you send these by email, you know the drill. — If your file is set up something like this, so let's say I have different sheets for different countries and different managers are responsible for each country. So, let's say Tom is responsible for the UK, I would go to file, save as, give it a name, save it as PDF, — then I'll open Outlook, click on new email, put in Tom's email address, add a subject, browse for the file, type in some text here, and then hit send. And then I would go back to Excel and repeat this all over again for the next person and the next person. Now, I used to have a VBA macro that did all of this for me, but then the world started moving to Excel online and VBA just doesn't work there. Plus, in many companies, IT doesn't allow the use of VBA anymore. Now, the good news is that Microsoft quietly gave Excel the ability to create PDFs and send emails directly from Excel. There's no VBA, there's no Power Automate. So, watch this. Over here, I have an index sheet with a table that states the

### [1:15](https://www.youtube.com/watch?v=RwcEa9fJsAk&t=75s) Setting Up Your Dashboard: The Data Table Structure

manager's name, their email address, and the worksheets that should get sent to them. All I have to do is click this button and their sheet is sent as a PDF document. Now, it doesn't matter if you click this button in Excel and desktop or if you go to Excel online and you click this button there, they both work the same. So, here we can test it out. I'm just going to click this. Actually, before I do that, let me quickly bring up Prakash's email so that we can take a look. Yes, so that's Prakash. He should be receiving the PDF for Canada. Now, I'm going to click this and let's just see how long it's going to take to arrive. Here we can see there are things happening in the background and here it is. And we have, "Hi Prakash, please find attached your report. " When I open this, we just see the info for Canada. Now, I did hear another ping and that was for Tom. Let me just bring up Tom's email and here we have, "Hi Tom, please find attached your report. " And this one is for the UK. You probably want to know how this is set up. We're going to build up to that. We'll start simple first and I'll take you through the steps. It's quite simple, it's easy to follow, and you can also check the link in the description and grab the file and the code that I'm using. Now, by code, I

### [2:45](https://www.youtube.com/watch?v=RwcEa9fJsAk&t=165s) Introduction to Office Scripts & The Automate Tab

mean Office Scripts. So, this button here uses Office Scripts to figure out which sheet to send, it converts to PDF, and then it sends it with an email. Now, if you're wondering whether each person is restricted to a single sheet, no, the code has been set up so that it works like this. So, in this case, Prakash, let's say he's responsible for both Canada and Germany. When I click this, Prakash will receive one PDF that includes both Canada and Germany, and it looks like this. If you've never used Office Scripts before, now is a great time to test it out. Just go to the Automate tab, new script, create in code editor, and you get the Office Scripts box pop up on the side. Think of this as VBA's younger sibling. It's the same idea, you automate stuff in Excel, but it works in Excel online as well, which VBA doesn't. Notice we got some placeholder code here. I'm going to expand this so we can see it better, and I'll also increase the font size a little bit so that's easier to read. This here, this top part, that first line, is the entry for Excel. So, it needs this for the script to run. The rest is just placeholder code that we can replace. To convert a file into PDF and send it with email, we can actually grab the code directly from Microsoft Learn. I'll add the link for this in the

### [4:10](https://www.youtube.com/watch?v=RwcEa9fJsAk&t=250s) Script Walkthrough: Understanding convertToPdf & sendMail

description. If I scroll down, we can see the code. Since this is the full code, so we have that entry point here as well, I can copy this whole thing, go back to Excel, and let's just paste it in. It's not a very long script. There are bits and pieces that we can see we need to adjust. So, let me just quickly walk you through this. After our entry point, we're converting the Excel file into a PDF. So, convert to PDF is the method that we're using and we're assigning it to PDF object. Now, you can change these names if you want, but we can stick to these standard names. Then here, we're defining a name for our PDF file. So, in this case, this is just called report. pdf. I can call it regionalreport. pdf. Then here's the code to download the PDF. But if you don't need to download the PDF, you just want to send it directly with email, you actually don't need this. So, notice these double slashes here, these are comments that tell us what's happening in the code. This part is to download the PDF. If you don't want it, we can just get rid of this code, or you can comment out the entire code if you're not sure or and you might want to use it later on. This part here is where we email the PDF. So, we're using office script. send email. This is where you need to make your adjustments. So, let's say I'm sending this one to Prakash@excelplus. com. Subject, I'm just going to go with regional report and here's the monthly performance report. And for attachments, we have PDF file, which we defined up here. Now, you can also attach multiple PDF files. Okay, so with this set up like this, I'm just going to click on play and let's run this. See what we get. The script ran successfully. We should get an email right now. Here we have it. Prakash got the regional report. Now, when I take a look at what's inside, it has everything. The full file was converted to a PDF and sent with an

### [6:30](https://www.youtube.com/watch?v=RwcEa9fJsAk&t=390s) Customizing the Code for Multiple Recipients

email. And all it took were these few lines of code. That's it. But there is a problem. It has everything, all the countries and sheets. Maybe I don't want Prakash to see everything. Maybe there are some sheets that are anyhow should be excluded or not needed, like the index sheet. I might have some other sheets. So, I thought, well, the convert to PDF method might take some additional arguments where I could specify which sheets to keep or which sheets to drop. But unfortunately, that's not the case, at least not yet. What it does is it converts the entire workbook to a PDF. So, I thought, well, I'm kind of stuck. Not exactly. Here's the trick. If I hide a sheet, so if I hide this, let's actually hide multiple sheets. Let me just select this, hide these. Now, let's run the script. Let's click on run and Prakash should now receive only United States data. Let's check it out. Here it is. Let's open it up. And we just have the USA sheet. Let me quickly unhide everything. Let's unhide. Select everything, just hold down shift, click on the last one, and okay. So, the trick is before we create the PDF, we hide every sheet that we don't want. And then we create the PDF. Once we're done, we unhide everything again so our workbook goes back to normal. And this way, the manager gets a clean PDF with only their data. Now, obviously, I'm not going to sit here and manually hide every sheet and then update this email address so that the correct manager gets it. I want to automate everything. This

### [8:20](https://www.youtube.com/watch?v=RwcEa9fJsAk&t=500s) Adding the Automation Button to Your Sheet

is where our index sheet comes into play. I can define everything in the cells here and I can get the Office Scripts to go through each row, grab the name, grab the email, and grab the sheet or sheets that are relevant for that manager, and send it to them as a PDF. I'm just going to paste in the code here. Let's remove this and paste in the updated code. Now, the version that I have here looks through a range, not a table. I'll show you the table version in a second. So, if you're using this in your own Excel files, make sure you update the sheet name, mine is index, and you update the range where your data starts. So, mine is right now from B5 to D6. Then we loop through each row, and then if we have multiple sheets assigned to a manager, we split the sheet names by a comma, so that's where we take care of multiple sheets. We make any target sheets visible first because we're going to run into an error if we hide everything. So, just to make sure that doesn't happen, we make the sheets visible and then we hide the stuff that we don't want. Then we convert to PDF, and then we add a personal message. Once we're done, we make all the sheets visible again. Now, don't worry, you don't have to write this from scratch. Just download the workbook. You're going

### [9:50](https://www.youtube.com/watch?v=RwcEa9fJsAk&t=590s) Live Demo: Bulk Emailing PDF Reports

to find the link in the description and you're going to see the code there. Now, once you have your script, it's also good practice to give your script a proper name, right? So, script 11 doesn't mean much. Let's go ahead and rename it. I'll call it convert to PDF range and enter. You might have to wait a little bit and then you're going to see it become available in your Office Scripts gallery here. So, all you would need to do is select it and run it. The thing that I didn't really like about this version was that I'm referencing a range. I would prefer to reference a table. Like this makes it a lot more dynamic. So, I created a version here, which I realize now has a typo in the name. So, let me just go and edit this. This is the version that uses a table. The table is called sent list. Right? So, if I go to table design, sent list. If you're using a different table name, just make sure you update this bit in the code. Now, I also added some debugging to this. So, you're going to notice that this code is longer and that's for cases when someone types in a wrong sheet name. So, what if the sheet

### [11:05](https://www.youtube.com/watch?v=RwcEa9fJsAk&t=665s) Troubleshooting & Common Script Errors

doesn't exist? If I don't account for that, then the code is going to run into an error. What if some bits are empty? What if the email is empty? So, to account for that, I've added some error handling. So, in case we have empty rows or a sheet doesn't exist, that row is skipped. Okay, so once this is set up, you can just click on run and run the code. Or if you want to add a button to your report like the one I have here, click on this more options and add it in the workbook. And then, you just need to run this and your emails are automatically sent. So, if I bring up Tom's Outlook, here Tom has received a personal message with the PDF for the country that he's responsible for. And if I bring up Prakash's email, he's received the countries that he's responsible for. Now, you might notice there's a time difference here. That's because Prakash is located in India, so there's a time difference between where Tom is located. So, that's Office Scripts. Now, the advantage of Office Scripts is that it works on desktop as well as on Excel online. And we didn't need to combine it with other tools like Power Automate. We got everything in this one script. And don't forget, you can download the file from the link in the description. Now, if you're a fan of automation, you're going to love our Automate Excel Recipes course, which takes a

### [12:30](https://www.youtube.com/watch?v=RwcEa9fJsAk&t=750s) Final Tips: Moving from VBA to Office Scripts

look at lots of different realistic cases and takes you through different tools you can use to automate the entire process. So, from Power Query, Power Automate, and some Office Scripts as well. You guys should check that out as well if you're interested. Thank you for watching. Thank you for being here. I know this was a bit of a longer video. I hope you enjoyed it and I'll catch you in the next video.

---
*Источник: https://ekstraktznaniy.ru/video/51386*