Excel to Outlook Template help

Romuline

New Member
Joined
Feb 21, 2013
Messages
2
Hi there I am struggling with a bit of coding that hopefully someone can help me with. Basically I am trying to create an email using a template but I would like to populate parts of the template with data that is contained within cells in Excel.
Now I have the code and can create the email, populate the subject and the To fields from Excel and can populate the body of the email if it is empty, but I want to populate certain areas of the body that have pre determined text. E.g

Reporting Site : {Data imported from Excel}

Here is the code I have.

Sub SaveAsDraft()
Dim objOutlook As Object
Dim objMailMessage As Outlook.MailItem
Dim emlBody, sendTo As String
Dim wkbook As String
Application.ScreenUpdating = False
Set objOutlook = CreateObject("Outlook.Application")
Set objMailMessage = objOutlook.CreateItemFromTemplate("C:\Documents and Settings\Work\Desktop\Alert.oft")
sendTo = "#All Users"
emlBody = Range("A6")
With objMailMessage
.To = sendTo
.Body = emlBody
.Subject = "Sev " & Range("A1") & Range("A2") & Range("A3") & Range("A4")
.Display
.Save
.Close olPromtForSave
End With
End Sub

Thanks in advance for any help
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
One way is by putting placeholders in the template's email body, such as [A1], [A2], denoting the cell which populates that part of the template. Then use the VBA Replace function to replace each placeholder with the appropriate cell value, like this:
Code:
        .Body = Replace(.Body, "[A1]", Range("A1").Value)
        .Body = Replace(.Body, "[A2]", Range("A2").Value)
 
Upvote 0

Forum statistics

Threads
1,223,250
Messages
6,171,036
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top