In Microsoft Excel, you can send a section of a workbook as
an e-mail message. This article contains sample Microsoft Visual Basic for
Applications (VBA) code that demonstrates how to automate sending a range of
cells in an e-mail message.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
The following VBA code sample sends a range of ten
cells, A1 through B5, from the currently active workbook to the e-mail address
specified in the code:
' Select the range of cells on the active worksheet.
' Show the envelope on the ActiveWorkbook.
ActiveWorkbook.EnvelopeVisible = True
' Set the optional introduction field thats adds
' some header text to the email body. It also sets
' the To and Subject lines. Finally the message
' is sent.
.Introduction = "This is a sample worksheet."
.Item.To = "E-Mail_Address_Here"
.Item.Subject = "My subject"
This code only works with Microsoft Outlook. It does not work
with any version of Microsoft Outlook Express.
with the e-mail address that you
want to send the range to.Note
Item.Send in the code triggers an Outlook security warning to
display the following message: Click
to allow the mail to be sent.
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
Description of the developer-related e-mail security features in Outlook 2002