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.
ThisWorkbook.SendMail "firstname.lastname@example.org", "Sample Workbook"
Explanation:In the above example it will send the activeworkbook as an attachment to email@example.com 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.
.SendMail Recipients:="firstname.lastname@example.org", Subject:="Sample Workbook"
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.