Instructions for sending emails from Excel spreadsheets using VBA scripts

Using VBA scripts in Excel does not require any programming knowledge. VBA helps you do many advanced tasks such as creating a spreadsheet report containing all PC information, emailing directly from a spreadsheet ...

To send email from Microsoft Excel just need a few simple scripts. Do not be afraid to add this feature to your spreadsheet if you want to really get the most out of Excel office software .

Email from Excel

There are many reasons why you want to send email right at Microsoft Excel. For example: Your employees update documents and spreadsheets weekly and you want to receive email notifications when that action is complete or sometimes, you want to email all contacts in a same workbook. at…

You must have thought of using a complicated Excel emailing script, but it's actually very simple. This article will guide you to take advantage of a feature that has long been available in Excel VBA, called Collaboration Data Objects (CDO) .

Instructions for sending emails from Excel spreadsheets using VBA scripts

CDO is a messaging component used in Windows right from the early versions. It used to be called CDONTS. After Windows 2000 & XP was born, "CDO for Windows 2000" replaced it. This component is included in the VBA installation in Microsoft Word or Excel and is available for use at any time.

Using this component to email in Windows products with VBA is extremely easy. For example, this article uses CDO in Excel to send emails that contain results in one cell.

Step 1: Create a VBA Macro

First, go to Excel Developer tab > click Insert in Controls panel , then select a command button.

Instructions for sending emails from Excel spreadsheets using VBA scripts

Drag it into this worksheet, then create a new macro by clicking Macros in the Developer ribbon.

Instructions for sending emails from Excel spreadsheets using VBA scripts

When you click the Create button , it opens the VBA editor.

Add a reference to the CDO library by navigating to Tools> References in the editor.

Instructions for sending emails from Excel spreadsheets using VBA scripts

Scroll down the list until you see Microsoft CDO for Windows 2000 Library . Check the checkbox and click OK .

Instructions for sending emails from Excel spreadsheets using VBA scripts

When you click OK , note the name of the function where the script is pasted, because you will need it later.

Step 2: Set the CDO fields "From" and "To"

To do this, you first need to create email-related objects and set up all the required email delivery fields.

Remember that many fields may or may not, but From and To are required.

Dim CDO_Mail As Object
Dim CDO_Config As Object
Dim SMTP_Config As Variant
Dim strSubject As String
Dim strFrom As String
Dim strTo As String
Dim strCc As String
Dim strBcc As String
Dim strBody As String

strSubject = "Results from Excel Spreadsheet"
strFrom = "[email protected]"
strTo = "[email protected]"
strCc = ""
strBcc = ""
strBody = "The total results for this quarter are:" & Str (Sheet1 .Cells (2, 1))

The interesting thing is that you can create any desired string to customize the entire email message and assign it the strBody variable.

Piecing together the contents of an email message using a string & to insert data from any Microsoft Excel spreadsheet right in an email (as shown above).

Step 3: Configure CDO to use external SMTP

The next piece of code is where you configure CDO to use any external SMTP server to send email.

This example does not set up SSL via Gmail, CDO can replace SSL but it is outside the scope of this article. If you need to use SSL, the advanced code in Github can help you.

Set CDO_Mail = CreateObject ("CDO.Message")
On Error GoTo Error_Handling

Set CDO_Config = CreateObject ("CDO.Configuration")
CDO_Config.Load -1

Set SMTP_Config = CDO_Config.Fields

With SMTP_Config
.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp. gmail.com "
.Item (" http://schemas.microsoft.com/cdo/configuration/smtpauthenticate ") = 1
.Item (" http://schemas.microsoft.com/cdo/configuration/sendusername ") =" [email protected] "
.Item (" http://schemas.microsoft.com/cdo/configuration/sendpassword ") =" password "
.Item (" http://schemas.microsoft.com/cdo/configuration/smtpserverport ") = 25
.Item (" http://schemas.microsoft.com/cdo/configuration/smtpusessl ") = True
.Update
End With

With CDO_Mail
Set .Configuration = CDO_Config
End With

Step 4: Complete CDO setup

You have now configured your SMTP server to send email. All you have to do is fill in the appropriate fields for the CDO_Mail object and issue the Send command .

Here's how to do it:

CDO_Mail.Subject = strSubject
CDO_Mail.From = strFrom
CDO_Mail.To = strTo
CDO_Mail.TextBody = strBody
CDO_Mail.CC = strCc
CDO_Mail.BCC = strBcc
CDO_Mail.Send

Error_Handling:
If Err.Description <> "" Then MsgBox Err.Description

None of the pop-ups or security alerts appear as you usually see when using the Outlook email object.

CDO simply puts email components side by side and uses server connection details to enable sending information. This is the easiest way to combine emails into Microsoft Word or Excel VBA scripts.

To connect the command button to this script, access the code editor and click Sheet1 to see the VBA code of that worksheet.

Type the name of the function where you pasted the script above.

Instructions for sending emails from Excel spreadsheets using VBA scripts

This is the information you receive in the inbox.

Instructions for sending emails from Excel spreadsheets using VBA scripts

Note : If you receive the error The transport failed to connect to the server , make sure you have entered the correct username, password, SMTP server and port number in the code line listed at With SMTP_Config .

Enhance and automate the whole process

Sending emails from Excel with one button is really safe and convenient. If you want to use this feature often, you can automate it.

To do this, you need to change the macro. Go to the Visual Basic Editor, copy and paste the entire code gathered. Next, select ThisWorkbook from the Project hierarchy .

From the two drop-down fields at the top of the code window, select Workbook and click Open from the Methods menu . Paste the email script above into Private Sub Workbook_Open () . This action will run the macro whenever you open the Excel file.

Instructions for sending emails from Excel spreadsheets using VBA scripts

Next, open Task Scheduler . You will use this tool to ask Windows to automatically open spreadsheets at specified intervals. At that time, your macro will be activated and emailed.

Instructions for sending emails from Excel spreadsheets using VBA scripts

Select Create Basic Task ... from the Action menu and follow the instructions until you reach the Action screen.

Select Start a program and click Next .

Instructions for sending emails from Excel spreadsheets using VBA scripts

Use the Browse button to find the Microsoft Excel location on the computer or copy & paste the path in the Program / script field .

Then enter the path to the Microsoft Excel document in the Add arguments field .

Complete instructions and schedule you will be made.

You should test this feature by scheduling the action in the next few minutes, then revising the task after you see it working effectively.

Note : You may need to adjust the Trust Center settings to make sure that macro runs as follows:

Open the spreadsheet and navigate to File> Options> Trust Center .

Here, click Trust Center Settings . On the next screen, select Never show information about blocked content .

Microsoft Excel is an extremely powerful tool, but learning how to use it can sometimes be challenging for many. If you want to master this software, you need to know how to use VBA. It is not easy.

However, with a little VBA experience, you can automate basic tasks on Microsoft Excel and have more time focusing on more important tasks.

Hope the article is helpful to you. Good luck!

Sign up and earn $1000 a day ⋙

Exploring the Features of IP Anonymizer Database

Exploring the Features of IP Anonymizer Database

In an era where online privacy and data protection have become paramount concerns for individuals and organizations alike, the need for effective tools to safeguard personal information is more critical than ever. The IP Anonymizer Database emerges as a vital resource for those seeking to navigate the complexities of digital anonymity.

TOP AI tools help you add color to old black and white photos

TOP AI tools help you add color to old black and white photos

TOP AI tools help you add color to old black and white photos. If you want to add color to old black & white photos, use one of the AI ​​tools below.

7 rules for storing a bank card

7 rules for storing a bank card

Each bank card is marked with important information - number, owner’s name, expiration date, CVC or CVV and a chip, thanks to which payments are made at terminals (including contactless). In order for this information to be preserved, it is important to treat the means of payment with care.

IObit Malware Fighter 11 Review 2024

IObit Malware Fighter 11 Review 2024

When your computer gets attacked by a virus or malware, you’ll certainly such for a powerful antivirus to fight back. Well, IObit Malware Fighter is exactly what you need. From its name alone, you can be certain that you are getting the tough protection your computer needs.

How To Find Quality And Fast Internet In Montreal

How To Find Quality And Fast Internet In Montreal

Montreal, a city brimming with culture, history, and Poutine (a famous Canadian dish), deserves an internet connection that can keep up. Whether you’re a streamer glued to Twitch, a workaholic juggling video conferences, or a casual web surfer, a reliable and fast internet plan is essential.

Google Drive for desktop will be discontinued in March 2018

Google Drive for desktop will be discontinued in March 2018

Google Drive for desktop will be discontinued in March 2018, Google has officially announced that it will stop supporting Google Drive for desktop and then the company will remove the application.

Simple ways to fix AirDrop not working error

Simple ways to fix AirDrop not working error

Simple ways to fix AirDrop not working error, AirDrop not working on iPhone, iPad, Mac what to do? This article will provide you with simple ways

TOP best computer screen recording software 2024

TOP best computer screen recording software 2024

TOP best computer screen recording software 2024, Which is the best lightweight, free, high-quality computer screen recording software? Let's find out the top with WebTech360

What is an email address? How to get an email address?

What is an email address? How to get an email address?

What is an email address? How to get an email address?, What is an email address? What is email address entry? This article will answer all your related questions

Every WhatsApp shortcut for computer you need to know

Every WhatsApp shortcut for computer you need to know

Every WhatsApp shortcut for your computer you need to know, WhatsApp is one of the most popular free messaging apps today. The keyboard shortcuts below will help

Unlocking Baccarats Social Thrills: Tedbets Global Gaming Hub

Unlocking Baccarats Social Thrills: Tedbets Global Gaming Hub

Discover the vibrant social scene of baccarat on Tedbet, where players worldwide connect, chat, and enjoy the excitement of live dealer games.

Summary of how to find videos on TikTok

Summary of how to find videos on TikTok

Summary of how to find videos on TikTok, Finding videos on TikTok is not difficult. Let's learn together how to find the original video on TikTok or find the Tik Tok clip you want to watch

Improved mouse sensitivity for Free Fire on BlueStacks

Improved mouse sensitivity for Free Fire on BlueStacks

Improved mouse sensitivity for Free Fire on BlueStacks, BlueStacks has made important improvements for Free Fire gamers. Please upgrade BlueStacks 4.230.10

Huang you: Butter Camera sparkling photo editing app

Huang you: Butter Camera sparkling photo editing app

Huang you: Sparkling photo editing application Butter Camera, Huang you (黄油 相机) is an extremely hot Chinese editing application today, here we would like to invite you

Tips for using Chrome Web Store you need to know

Tips for using Chrome Web Store you need to know

Tips for using Chrome Web Store you need to know, Chrome Web Store or Chrome Web Store offers a selection of apps, extensions and stylish browser wallpapers

What is CapCut? Is it safe to use CapCut?

What is CapCut? Is it safe to use CapCut?

What is CapCut? Is it safe to use CapCut?, What is CapCut? Is music on CapCut copyrighted? Let's find out with WebTech360 what you need to know about CapCut!

Why is buying TikTok coins cheaper on PC?

Why is buying TikTok coins cheaper on PC?

Why is it cheaper to buy TikTok coins on PC?, TikTok gives users the option to exchange real money for coins in the app. However, buying TikTok coins on PC is cheap

How much Internet capacity does Zoom use?

How much Internet capacity does Zoom use?

How much Internet capacity does Zoom use?, Zoom is an indispensable remote online learning and working software during the epidemic, but it can be extremely bandwidth-consuming.

EmuOS: Relive your childhood with legendary games of the past

EmuOS: Relive your childhood with legendary games of the past

EmuOS: Relive your childhood with legendary games of the past, EmuOS is a Web interface that simulates basic Windows 3.1, 95, 98, NT operating systems that provide a lot

TOP best ways to open and read PDF files on your computer

TOP best ways to open and read PDF files on your computer

TOP best ways to open and read PDF files on your computer. How to open PDF files on your computer is not too difficult. In fact, you have many ways to read PDF files. Join WebTech360