E-mail the contents of your Excel file using VBA
The below code mails a range of 20 cells, A1 through B10, from the currently active workbook to the e-mail address specified in the code:
Sub EmailRange()
' Select the range of cells on the active worksheet.
ActiveSheet.Range("A1:B10").Select
' 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.
With ActiveSheet.MailEnvelope
.Introduction = "This is a sample worksheet."
.Item.To = "SomeOne@XYZ.com"
.Item.Subject = "subject line"
.Item.Send
End With
End Sub
Note This code only works with Microsoft Outlook. Replace E-Mail Address here 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:
A program is trying to automatically send e-mail on your behalf. Do you want to allow this? If this is unexpected, it may be a virus and you should choose "No".
Click Yes to allow the mail to be sent.
- aprajitaj's blog
- Login or register to post comments
- 3487 reads
Recent comments
5 years 36 weeks ago
6 years 22 weeks ago
6 years 34 weeks ago
6 years 37 weeks ago
6 years 38 weeks ago
6 years 43 weeks ago
6 years 52 weeks ago
7 years 2 days ago
7 years 3 days ago
7 years 3 days ago