SendMail Workbook method is used to sends the workbook via an email as an attachment by using the installed mail system.
50+ Project Management Templates Pack
Excel PowerPoint Word
Advanced Project Plan & Portfolio Template
Ultimate Project Management Template
20+ Excel Project Management Pack
20+ PowerPoint Project Management Pack
10+ MS Word Project Management Pack
When we use SendMail Workbook Method in VBA?
We use SendMail workbook method when we wanted to send an email to the specified recipients and workbook as an attachment. We can also send particular worksheet as workbook.
VBA SendMail Workbook Method- Syntax
Here is the syntax of SendMail workbook method in VBA.
Workbooks(“Your Workbook Name”).SendMail(Recipients,
Recipients: It is required parameter. It specifies the name of the recipient(s) and added as To recipients.
Subject: It is an Optional parameter. It specifies the subject of the message. If you don’t specify any name, Default name is document name.
ReturnReceipt: It is an Optional parameter. Default value is False. If it is True notifies the sender when recipient receives an email.
VBA SendMail Workbook Method: Example 1
Please find the below example, it will show you how to send an email using SendMail workbook method using VBA.
Sub End_Email() ThisWorkbook.SendMail "email@example.com", "Sample Workbook" End Sub
Explanation:In the above example it will send the activeworkbook as an attachment to firstname.lastname@example.org and subject is ‘Sample Workbook’.
VBA SendMail Workbook Method: Example 2
Please find the one more example, it will send one worksheet from a workbook.
Sub Send_Worksheet() ThisWorkbook.Sheets(“Sheet1”).Copy With ActiveWorkbook .SendMail Recipients:="email@example.com", Subject:="Sample Workbook" .Close SaveChanges:=False End With End Sub
Explanation: It will create a new workbook with which we are copying worksheet and send as an attachment. And then finally it closes the new workbook which we created without saving.
VBA SendMail Workbook Method – Instructions
Please follow the below step by step instructions to execute the above mentioned VBA macros or codes:
- Open an Excel Workbook
- Press Alt+F11 to Open VBA Editor
- Insert a Module from Insert Menu
- Copy the above code for activating a range and Paste in the code window(VBA Editor)
- Save the file as macro enabled workbook
- Press ‘F5’ to run it or Keep Pressing ‘F8’ to debug the code line by line.
|Excel VBA Reference||Project Management Reference|