PDA

View Full Version : Content in Outlook email from range



Nicolaf
11-09-2012, 12:05 PM
Hi,

I have a code that copies a file and sends it to a specified address see below.

What I would like to do is in the Body part instead of putting a fixed message (eg. "Hello") I would like to put a reference to a text contained in a cell.

For example the text in Cell A10 of the worksheet that I have open (eg. Data.xls found in directory C:\Data.xls).

How do I do that?

:dunno :dunno :dunno


Sub Mail_Workbook_1()

Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
' Change the mail address and subject in the macro before you run it.
With OutMail
.To = "email address"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hello"
.Attachments.Add ActiveWorkbook.FullName
' You can add other files by uncommenting the following line.
'.Attachments.Add ("C:\test.txt")
' In place of the following statement, you can use ".Display" to
' display the mail.
.Send
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
End Sub

Kenneth Hobs
11-09-2012, 12:14 PM
.Body = Range("A1").Value