Sub SendTemplateWithImages() Dim OutApp As Object Dim OutMail As Object Dim doc As Object Dim sh As Worksheet Set sh = ThisWorkbook.Sheets("Sheet1") ' Ensure this matches your sheet name Dim i As Integer i = 2 ' Starting row for data Set OutApp = CreateObject("Outlook.Application") ' Loop through rows until Template Path is empty Do While sh.Cells(i, 1).Value <> "" ' 1. Open your existing Outlook Template (.oft) Set OutMail = OutApp.CreateItemFromTemplate(sh.Cells(i, 1).Value) With OutMail .To = sh.Cells(i, 2).Value ' 2. Replace Text Placeholders in the Body ' Ensure your .oft template contains these tags: {System}, {Impact} .HTMLBody = Replace(.HTMLBody, "{System}", sh.Cells(i, 3).Value) .HTMLBody = Replace(.HTMLBody, "{Impact}", sh.Cells(i, 4).Value) ' 3. Handle the Image ' We insert the image at the very top of the email Dim imgPath As String imgPath = sh.Cells(i, 5).Value If imgPath <> "" Then ' This wraps the existing body with your custom image .HTMLBody = "<img src='" & imgPath & "' style='width:100%;max-width:600px;'><br><br>" & .HTMLBody End If .Display ' Use .Send to send automatically, .Display to review first End With i = i + 1 Loop Set OutMail = Nothing Set OutApp = NothingEnd Sub
ORACLE DATABASE ADMINISTRATION
ORACLE DATABASE ADMINISTRATION
recent posts
about
Posted in Uncategorized
Leave a comment