How to: Send Workbooks by E-Mail Programmatically

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Excel 2003

  • Excel 2007

For more information, see Features Available by Application and Project Type.

You can send a workbook as an e-mail attachment. However, you cannot add text to the message you send.

Note

You must be online and connected to your e-mail system to send e-mail. SendMail uses the Messaging Application Programming Interface (MAPI).

To send a workbook as an e-mail attachment in a document-level customization

  • Call the SendMail method of the workbook and specify recipients and optionally a subject.

    Globals.ThisWorkbook.SendMail(Recipients:="someone@example.com", Subject:="July Sales Figures")
    
    Globals.ThisWorkbook.SendMail("someone@example.com", "July Sales Figures", missing);
    

To send a workbook as an e-mail attachment in an application-level add-in

  • Call the SendMail(Object, Object, Object) method of the workbook and specify recipients and optionally a subject.

    Me.Application.ActiveWorkbook.SendMail(Recipients:="someone@example.com", Subject:="July Sales Figures")
    
    this.Application.ActiveWorkbook.SendMail("someone@example.com", "July Sales Figures", missing);
    

See Also

Tasks

How to: Run Excel Calculations Programmatically

Concepts

Working with Workbooks

Workbook Host Item

Global Access to Objects in Visual Studio Tools for Office Projects

The Variable missing and Optional Parameters in Office Solutions

Change History

Date

History

Reason

July 2008

Added a code example that can be used in an application-level add-in.

Customer feedback.