1 min readfrom Microsoft Excel | Help & Support with your Formula, Macro, and VBA problems | A Reddit Community

Macro sending selected cells to email, encountering error on VBA code

Hi all. I'm trying to simulate sending a selected range of cells "B2:D15" using email. I got a sample code here Macro that Automatically Sends content via Email : r/excel

However, while it creates the email, the body of the email is not displaying the ranges selected. I tried tweaking the code to no avail.

I tried using .Body from .HTMLbody to no avail. Here's the current code

Sub CreateEmail()

Dim ws As Worksheet

Dim rng As Range

Dim OutApp As Object

Dim OutMail As Object

Set ws = ThisWorkbook.Sheets("subject")

Set rng = ws.Range("$B$2:$D$15")

Set OutApp = CreateObject("Outlook.Application")

Set OutMail = OutApp.CreateItem(0)

On Error Resume Next

With OutMail

.To = "my email" ' Enter the email address of the recipient

.CC = "my email" ' Enter the email address of any CC recipients

.Subject = "subject" ' Enter the subject of the email

.Body = rng

.Display

End With

On Error GoTo 0

Set OutMail = Nothing

Set OutApp = Nothing

End Sub

submitted by /u/suwampert
[link] [comments]

Want to read more?

Check out the full article on the original site

View original article

Tagged with

#no-code spreadsheet solutions
#Excel compatibility
#Excel alternatives for data analysis
#rows.com
#financial modeling with spreadsheets
#google sheets
#VBA
#Macro
#Outlook.Application
#CreateEmail
#Range
#ws
#OutMail
#Email
#Body
#HTMLbody
#Worksheet
#selected range
#$B$2:$D$15
#On Error Resume Next