Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to put data in the body of an email using VBA in Outlook

Status
Not open for further replies.

Mizzness

Programmer
May 2, 2003
174
US
All.

I am trying to attach, via copy/paste value, data in a worksheet to the body of an e-mail.
The data is in worksheet "Template" and will be using the range of A1:H15.
What I would like is to have the macro copy/paste value the range into the body of the e-mail.
I already have the code set up to attach the file I'm using.
How can incorporate this ?

The code is as follows:

Application.ActiveWorkbook.Worksheets("Monthly Pricing").Activate

ESubject = "Subject"

SendTo = "Smith.john@abc.com"
Subject = "PV_Aging Analysis"
Ebody = ""
NewFileName = "U:\MBS\USERS\MBS PV\mrkvar\Misc\New Business\PV_Aging Analysis-Dec.xls"
Set App = CreateObject("Outlook.Application")
Set Itm = App.CreateItem(0)
With Itm
.Subject = "PV_Aging Analysis"
.To = SendTo
.Body = Ebody
.Attachments.Add "U:\MBS\USERS\MBS PV\mrkvar\Misc\New Business\PV_Aging Analysis-Dec.xls"
.Send
End With
Set App = Nothing
Set Itm = Nothing
'
End Sub

'
End Sub

Thanx for any & all help.
 
Chance,

I already have the code setup for sending the workbook.
I need the macro to incorporate the copy/paste value funcion as I have described above.

Can this be done ?

Thanx.
 
This is what I use.

Code:
Public Sub HTML_Email()

Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim FSObj As Scripting.FileSystemObject
Dim TStream As Scripting.TextStream
Dim rngeSend As Range
Dim strHTMLBody As String


'Select the range to be sent
Set rngeSend = Application.Range("B1:G35")

'Now create the HTML file
ActiveWorkbook.PublishObjects.Add(xlSourceRange, "C:\sales\tempsht.htm", rngeSend.Parent.Name, rngeSend.Address, xlHtmlStatic).Publish True


'Create an instance of Outlook (or use existing instance if it already exists
Set olApp = CreateObject("Outlook.Application")

'Create a mail item
Set olMail = olApp.CreateItem(olMailItem)

'Open the HTML file using the FilesystemObject into a TextStream object
Set FSObj = New Scripting.FileSystemObject
Set TStream = FSObj.OpenTextFile("C:\sales\tempsht.htm", ForReading)

strHTMLBody = TStream.ReadAll

olMail.HTMLBody = strHTMLBody
olMail.To = "joe@anywhere.com"
olMail.Subject = "HTML Email"
olMail.Send

End Sub

You will need to add the following references

Microsoft Scripting Runtime
Microsoft Script Control 1.0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top