VB and VBA Users Source Code: Email a workbook using Excel
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Email a workbook using Excel
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Monday, March 26, 2001
Hits:
877
Category:
Internet/Remote Comms
Article:
The following code demonstrates how to send an email using Microsoft's Excel built in SendMail method: Option Explicit 'Purpose : Sends an Email containing a workbook to a specified email account. 'Inputs : oWorkbook The workbook to send. ' sEmailAddress The email address to send the workbook to. ' [sSubject] The subject title of the email. 'Outputs : Returns True if succeeded in sending the email. 'Author : Andrew Baker 'Date : 11/09/2000 'Notes : 'Revisions : Function WorkbookEMail(oWorkbook As Excel.Workbook, sEmailAddress As String, Optional sSubject As String) As Boolean On Error GoTo ErrFailed Select Case Application.MailSystem Case xlMAPI 'Use MAPI to email workbook oWorkbook.SendMail sEmailAddress, sSubject WorkbookEMail = True Case xlNoMailSystem 'no mail client installed WorkbookEMail = False Case Else 'Use the menu commands to send the workbook oWorkbook.Activate Application.CommandBars("worksheet menu bar").Controls("File").Controls("Send To").Controls("Mail Recipient...").Execute WorkbookEMail = True End Select Exit Function ErrFailed: Debug.Print Err.Description WorkbookEMail = False End Function 'Demonstration routine Sub Test() Debug.Print WorkbookEMail(ThisWorkbook, "myemailaddress@myserver.com", "Email Subject") End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder