This component is already included in your VBA installation within Microsoft Word or Excel and is ready for use. Using the component makes sending emails from within Windows products with VBA extremely easy. In this example, you'll use the CDO component in Excel to send out an email that will deliver the results from a specific Excel cell. This article was written by Jack Lloyd.Jack Lloyd is a Technology Writer and Editor for wikiHow. He has over two years of experience writing and editing technology-related articles.
- Outlook Email Sign In
- Hotmail Inbox
- Microsoft Office Excel online, free
- Microsoft Hotmail Sign In
- Excel Online Hotmail
- Excel Pelo Hotmail
- Excel En Linea Hotmail
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
- Go to the Microsoft Excel workbook and open the worksheet that you will embed the email message in, then click te Insert Object. In the Object dialog box, go to the Create from file tab, click the Browser button to find and select the email message that you haved saved in Step 1.
- Microsoft Excel is the industry leading spreadsheet software program, a powerful data visualization and analysis tool. Take your analytics to the next level with Excel.
- Your e-mail has been migrated to Mercury Network. Please visit to access your e-mail and bookmark/save the new site. While the appearance of Mercury’s webmail is a little different, the overall layout and organization is generally the same.
Summary: Microsoft Excel MVP Ron de Bruin provides several samples and a useful add-in that makes it easy for customers to send items from Excel with Outlook. From sending a workbook to sending items to multiple recipients, the code samples and add-in should become a part of your reference library. (8 printed pages)
Applies to: Microsoft Excel 2000 | Microsoft Excel 2002 | Microsoft Excel 2003 | Microsoft Excel 2007 | Microsoft Excel 2010 | Microsoft Outlook 2000 | Microsoft Outlook 2002 | Microsoft Outlook 2003 | Microsoft Outlook 2007 | Microsoft Outlook 2010
Provided by:Ron de Bruin, Microsoft Excel MVP | Frank Rice, Microsoft Corporation | About the Authors
Contents
Sending Outlook E-mail Messages from Excel
Mailing Workbooks as E-mail Attachments
Mailing Single Sheets as Attachments
Conclusion
Read Part Two: OfficeTalk: Using the Excel Object Model to Send Workbooks and Ranges through E-Mail with Outlook (Part 2 of 2)
Outlook Email Sign In
Sending Outlook E-mail Messages from Excel
This article features code samples that you can use to perform various e-mail functions from Microsoft Office Excel by using the Microsoft Office Outlook object model. Ron de Bruin, an Excel Most Valuable Professional (MVP) and a frequent contributor to the newsgroups, provides the samples and add-in. You can find many more samples and an excellent add-in (RDBMail Add-in) that gives you several e-mail options on the Ribbon user interface (UI), at Ron’s Web site.
Sending workbooks and workbook components from Excel with Outlook is a frequently requested activity. It is relatively easy to do much of this by using commands on the Ribbon UI. However, you may want more control over what you can send. Doing this by using Microsoft Visual Basic for Applications (VBA) in Excel is where developers can make the biggest impact.
One method to use is the SendMail method in the Excel object model. This method works very well but is limited in what it can do. You can find examples using the SendMail method and a link to download a useful add-in created by Ron de Bruin in the article titled Working with Excel Workbooks and Worksheets in E-Mail.
Note
The code samples that are presented in this article will only work with Microsoft Outlook. They will not work with Microsoft Outlook Express or Microsoft Windows Mail.
You need to be aware of two security features for Outlook 2002, Outlook 2003, Outlook 2007, and Outlook 2010. Note that these features are implemented through a security update in Outlook 2000:
Blocking of a customizable list of file attachments considered unsafe because they can be used to propagate viruses.
Pop-up confirmation dialog boxes that occur when a program accesses address-related properties or attempts to send a message.
For more information about Outlook 2007 and Outlook 2010, see the article titled Code Security Changes in Outlook 2007.
In the following sections, I describe some of the VBA code samples created by Ron de Bruin.
Mailing Workbooks as E-mail Attachments
The following subroutine sends the last saved version of the active workbook in an e-mail message. Change the mail address and subject in the macro before you run the procedure.
The following subroutine sends a newly created workbook as a copy of the ActiveWorkbook object. Before sending the workbook, it is saved with a date-time stamp. After the file is sent, the workbook is deleted from the hard disk drive.
Tip
In the previous example, the file wb2 is opened by using the Workbooks.Open method and then mailed, closed, and finally deleted. It is also possible to perform these operations on the file without first opening it. However, by opening the file, you can add code to perform other operations such as the following statement which inserts text and a date into cell A1. You can also perform other operations such as deleting a worksheet or range in the workbook before sending it.

wb2.Worksheets(1).Range('A1').Value = 'Copy created on ' & Format(Date, 'dd-mmm-yyyy')
wb2.Save
Early Binding
If you want to use IntelliSense help show you the properties and methods of objects as you type them into the VBA Code Editor, you can use early binding. For more information about early binding, see the Word MVP site.
To add early binding, follow these steps:
First, add a reference to the Outlook Object Library. Open the VBA editor by typing Alt +F11.
On the Tools menu, click References.
Select Outlook xx Object Library where xx is the version number such as the Microsoft Outlook 12.0 Object Library.
Next, replace the following three statements in the code:
With these three statements.
Mailing Single Sheets as Attachments


The following subroutine sends a newly created workbook with just a single sheet as the ActiveSheet object. The procedure saves the workbook before mailing with a date-time stamp. After the file is sent, the workbook is deleted from the hard disk. Change the mail address and subject in the macro before you run the procedure.
Note
For additional information about how to work with different versions of Excel, see the section following this code block.
Note
You can also use the following statement if you know the sheet you want to mail. It does not have to be the active sheet. Sheets('Sheet5').Copy
Additional Information
In the macro, you see that if Val(Application.Version) < 12 is true, the next statement is as follows: FileExtStr = '.xls': FileFormatNum = -4143. This value represents the workbook format for Excel versions 97 through 2003.
However, if you run the code in Excel 2007 or Excel 2010, the code will look at the file format of the parent workbook and save the new file in that format.
If the parent workbook is a macro-enabled file (.xlsm) and there is no code in the new workbook, the new file will be saved as a macro-free file (. xlsx). This way, the e-mail recipient can recognize that this is a macro-free file. If the parent workbook is not an .xlsx, .xlsm, or .xls file, the new workbook will be saved as an Excel binary file (.xlsb).
The following are the main formats in Excel 2007 and Excel 2010:

51 = xlOpenXMLWorkbook (macro-free file . xlsx)
52 = xlOpenXMLWorkbookMacroEnabled (macro-enabled file . xlsm)
50 = xlExcel12 (Excel binary workbook with or without macros .xlsb)
56 = xlExcel8 (Excel version 97 through 2003 format file .xls)
Hotmail Inbox
If you always want to save in a specific format, you can replace the following statements in the macro.
With one of these statements.
In addition to saving the workbook in an Excel file format, you can also save the single-sheet workbook to one of the following formats:
Comma separated value file (.csv)
Text file (.txt)
Printable file (.prn.)
You should use one of the following statements, respectively.
If you want to use IntelliSense help show you the properties and methods of objects as you type them into the VBA Code Editor, you can use early binding. See the previous section for more information about early binding.
Microsoft Office Excel online, free
To use early binding in this procedure, replace these three statements in the code.
With these three statements.
Conclusion
Microsoft Hotmail Sign In
In the second part of this article, you will see the procedures for additional ways to send mail from Excel to Outlook. To continue, read OfficeTalk: Using the Excel Object Model to Send Workbooks and Ranges through E-Mail with Outlook (Part 2 of 2)
Excel Online Hotmail
About the Authors
Excel Pelo Hotmail
Ron de Bruin is an Excel Most Valuable Professional (MVP) and a frequent contributor to the newsgroups. For more information, see Ron's Excel page.
Excel En Linea Hotmail
Frank Rice is a senior programming writer and frequent contributor to the Microsoft Office Developer Center.
