Sending Email With VBA: Learn In 11 Simple And Easy Steps
Có thể bạn quan tâm
Visual Basic for Applications or VBA is a powerful programming language yet easy and lets you automate Microsoft Excel to the fullest. One such automation is using VBA codes to integrate other Microsoft apps like Outlook, PowerPoint, and Word and increase productivity.
Sending email with VBA in Excel is one such integration that makes your life easier by automating spreadsheet or report mailing tasks. This tutorial will walk you through the steps of sending email with VBA from Excel in easy-to-follow steps.
Microsoft Outlook Object Library Activation
You need to set the send email object reference of Outlook since it’s an outside object for Excel VBA. Follow along with these steps:
- Save the existing Excel file as a Macro-enabled file by clicking on File > Save As > select a location and changing the Save as type.
- Press Alt+F11 to bring up the VBA code editor and click on Tools located on the top menu bar.
- From there, select References and then scroll the Available References list to find Microsoft Outlook 16.0 Object Library.
- Select the object and click Ok to exit the Available References list.
Sending Email With VBA: Write Codes and Execute
Now that you’ve enabled the Outlook object in Excel VBA, follow these steps to write the Excel macro and execute that:
- Make sure you’re on the VBA code editor interface. Now, look for the Insert tab on the top menu of Excel VBA.
- Click on Insert and then select Module to insert a module where you’ll be able to write VBA codes.
- Now, copy-paste the following VBA script into the newly-created module.
The above-mentioned code will send an email using your Outlook account to the email addresses mentioned in the code.
The email content is also available in the EmailItem.HTMLBody code line. Moreover, Excel VBA will automatically attach your source workbook to the email as an attachment.
You may make the following changes to personalize the addresses and email body text:
- Replace all the email addresses within the quote with your own Outlook contacts.
- Customize the EmailItem.Subject text inside the quote as you see fit.
- In the EmailItem.HTMLBody code, you can replace all the texts within the quotation mark using your own content.
- Now, run the VBA script by pressing F5.
For sending email with VBA successfully, you’ll need to configure Gmail account or the Outlook account in the standalone Outlook app of the Microsoft Office suite. Online browser-based Outlook won’t work with this VBA code.
Conclusion
Now that you’ve followed along with the aforementioned steps for sending email with VBA, it should be easier for you to automate mundane tasks in Excel. For example, let the spreadsheet file automatically send an email to you when collaborators update the worksheet. Also, send automated emails to customers when you update the order status column in Excel.
If you want more Excel automation using VBA, utilize the VBA timestamp coding to keep a log of spreadsheet changes.
Get daily tips in your inbox Newsletter Join 35,000+ other readers How to take screenshots on Ubuntu Linux How to Rotate Text in Excel: 3 Easy Methods Read Full Bio Tamal DasTamal is a freelance writer at AddictiveTips. After gaining substantial experience in technology, finance, and business processes in his previous job in an IT consulting company, he adopted writing as a full-time profession 3 years ago. While not writing about the latest technology, he loves to play COD and binge-watch
Latest from Author How to Check a Box in Word Doc How to Type an Em Dash: Top 5 MethodsTừ khóa » Visual Basic Code To Send Email From Excel
-
VBA Send Email From Excel - WallStreetMojo
-
How To Send Emails From An Excel Spreadsheet Using VBA Scripts
-
How To Send Email In Excel Using VBA? - Simplilearn
-
VBA To Automate Sending Email From Excel Table With Attachment ...
-
Send Emails With Attachments From Excel Using VBA And Outlook
-
VBA Send Emails From Excel Through Outlook
-
How To Send Emails From Using Excel VBA? - EduCBA
-
Send Email From Excel Using VBA And VBScript - Tutorial
-
Excel Macro To Send Email Automatically (3 Suitable Examples)
-
Sending Email To A List Of Recipients Using Excel And Outlook
-
VBA Send Email From Excel
-
Mail From Excel With Outlook (VBA) - Ron De Bruin Excel Automation
-
Send Emails Using VBA From Excel Sheet With Multiple Recipients