To transport emails from Microsoft Excel only requires a few unproblematic scripts. Add together this functionality to your spreadsheets and you can really enhance how much you lot tin accomplish in Excel.

We've covered a lot of keen Excel macros, which can accomplish the same things VBA scripts can, simply without the need for programming knowledge. Simply there are many advanced things you can merely do with VBA, like creating a spreadsheet written report with all of your PC data.

Prefer to watch this tutorial every bit a video? We've got you lot covered!

Why Send Email From Excel?

At that place are a lot of reasons why you might want to send an electronic mail from inside Microsoft Excel.

Peradventure you accept staff that updates documents or spreadsheets on a weekly basis, and yous'd similar to receive an email notification of when those updates are done. Or you might have a spreadsheet of contacts and yous desire to ship 1 electronic mail to all of them at in one case.

You're probably thinking that scripting an email broadcast from Excel is going to be complicated. That's non the example at all.

The technique in this article will brand use of a feature that's been available in Excel VBA for a long fourth dimension, Collaboration Data Objects (CDO).

collaboration data objects (CDO) in excel

CDO is a messaging component used in Windows since very early generations of the Bone. It used to be called CDONTS, and and so with the advent of Windows 2000 and XP, was replaced with "CDO for Windows 2000". This component is already included in your VBA installation inside Microsoft Discussion or Excel and is ready for use.

Using the component makes sending emails from within Windows products with VBA extremely piece of cake. In this instance, you'll use the CDO component in Excel to send out an electronic mail that will deliver the results from a specific Excel cell.

Step 1: Create a VBA Macro

The first step is to go to the Excel Developer tab.

Inside the Programmer tab, click on Insert in the Controls box, and then select a control push button.

adding button in excel

Draw information technology into the sheet and so create a new macro for it past clicking on Macros in the Developer ribbon.

add macro for command button

When you click the Create push button, it'll open the VBA editor.

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

adding references in excel

Curl downward the list until you find Microsoft CDO for Windows 2000 Library. Mark the checkbox and click OK.

adding cdo for windows reference

When you click OK, make notation of the proper noun of the function where you lot're pasting the script. You'll need it later.

Step 2: Set Upwards the CDO "From" and "To" Fields

To do this, you first need to create the mail objects and set upwardly all of the fields that are necessary to send the e-mail.

Proceed in mind that while many of the fields are optional, the From and To fields are required.

          Dim CDO_Mail As Object
Dim CDO_Config As Object
Dim SMTP_Config Every bit Variant
Dim strSubject As String
Dim strFrom As Cord
Dim strTo Equally String
Dim strCc As String
Dim strBcc Every bit String
Dim strBody As String
strSubject = "Results from Excel Spreadsheet"
strFrom = "rdube02@gmail.com"
strTo = "rdube02@gmail.com"
strCc = ""
strBcc = ""
strBody = "The total results for this quarter are: " & Str(Sheet1.Cells(ii, 1))

The cool matter about this is that you can create upwards any cord y'all want to customize a full email message and assign it to the strBody variable.

Piece together components of the message by using the & string to insert data from any of the Microsoft Excel sheets right into the email message, just similar shown above.

Step 3: Configure CDO to Utilize an External SMTP

The next department of lawmaking is where you volition configure CDO to use any external SMTP server to send the email.

This case is a not-SSL setup through Gmail. CDO is capable of SSL, but that's outside the scope of this commodity. If you need to utilise SSL, this advanced code in Github can help.

          Prepare CDO_Mail = CreateObject("CDO.Message")
On Mistake GoTo Error_Handling
Set CDO_Config = CreateObject("CDO.Configuration")
CDO_Config.Load -i
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") = "e-mail@website.com"
.Detail("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "countersign"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = Truthful
.Update
Stop With
With CDO_Mail
Set .Configuration = CDO_Config
End With

Step 4: Finalize the CDO Setup

At present that yous've configured the connexion to the SMTP server for sending the email, all you lot have to do is make full in the appropriate fields for the CDO_Mail object, and issue the Transport command.

Here is how you practise that:

          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

There won't be whatsoever pop-upwardly boxes or security alarm letters, which tin can happen when yous resort to using the Outlook mail object.

CDO only puts together the e-mail and utilizes your SMTP server connectedness details to burn off the message. It's the easiest way to incorporate email into Microsoft Discussion or Excel VBA scripts.

To connect your command push button to this script, become into the code editor and click on Sheet1 to view the VBA lawmaking for that worksheet.

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

connect command button to script

Here's what the message looked like that I received in my inbox:

excel email received

Note: If y'all receive an mistake that reads The transport failed to connect to the server, brand sure you've entered the correct username, password, SMTP server, and port number in the lines of lawmaking listed underneath With SMTP_Config.

Have It Farther and Automate the Whole Process

Information technology'southward all well and good to be able to transport electronic mail from Excel at the bear on of a button. Still, you might want to use this functionality on a regular basis, in which case it would make sense to automate the procedure.

To practise then, you lot'll need to brand a alter to the macro. Head to the Visual Basic Editor and copy and paste the entirety of the code we put together.

Side by side, select ThisWorkbook from the Projection hierarchy.

From the ii dropdown fields at the meridian of the code window, select Workbook and select Open from the Methods dropdown.

Paste the email script above into Individual Sub Workbook_Open().

This will run the macro whenever y'all open upwards the Excel file.

Paste the email script

Adjacent, open up upward Job Scheduler.

You lot're going to use this tool to inquire Windows to open up up the spreadsheet automatically at regular intervals, at which indicate your macro will be initiated, sending the email.

create basic task in task scheduler

Select Create Bones Task... from the Action carte du jour and work your way through the magician until you achieve the Action screen.

Select Commencement a plan and click Next.

select program task scheduler

Use the Browse button to find Microsoft Excel's location on your computer, or copy and paste the path into the Program/script field.

Then, enter the path to your Microsoft Excel document into the Add arguments field.

Complete the wizard, and your scheduling will exist in place.

Information technology's worth running a test by scheduling the action for a couple of minutes in the hereafter, then amending the job in one case you tin confirm that information technology'southward working.

Note: You may have to suit your Trust Center settings to ensure that the macro runs properly.

To do so, open the spreadsheet and navigate to File > Options > Trust Center.

From here, click Trust Center Settings, and on the next screen set the radio dial to Never evidence information most blocked content.

Brand Microsoft Excel Piece of work for You lot

Microsoft Excel is an incredibly powerful tool, but learning how to get the near out of it tin exist a little intimidating. If y'all desire to truly master the software, yous'll need to be comfortable with VBA, and that's no pocket-size job.

However, the results speak for themselves. With a little VBA experience under your belt, you'll soon be able to make Microsoft Excel perform basic tasks automatically, giving yous more time to concentrate on more pressing matters.

It takes time to build expertise with VBA, but you'll soon see the fruits of your labors if y'all tin stick with it.

One great place to first is our authoritative tutorial on using VBA in Excel. Once you lot're done with that, this simple script to send emails from Excel will feel similar child's play.

Clean up With a $150 Saving on Yeedi's Vac Station Robot Vacuum

Put your feet up and let Yeedi'due south bionic butler do all the hard work, including emptying its own dustbin!

Read Next

Near The Author