I am creating (trying to anyway) a VBA code that will generate an email. The data that will be emailed changes based on which employee I have selected (I have this part done). I have it so it generates an email and inserts a screenshot of my employee's metrics. The to, CC, and subject lines are all great as is. My problem is I'm struggling to indent certain lines.
Bonus points if you can get the word "monthly" on the first line to say last month's name instead of "month" (i.e. "Thank you for meeting with for your December 1 on 1" instead of "Thank you for meeting with me for your monthly 1 on 1"), I couldn't figure it out but that's the least of my worries really.
This is what the email currently looks like when it generates:
This is how I would like it to look (or similar):
Here is my code currently:
Sub send_email_with_metrics_as_pic()
Dim OutApp As Object
Dim OutMail As Object
Dim table As Range
Dim pic As Picture
Dim ws As Worksheet
Dim WordDoc
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
'grab table, convert to image, and cut
Set ws = ThisWorkbook.Sheets("Formulas")
Set table = Worksheets("Metrics Dashboard").Range("B6:M28")
ws.Activate
table.Copy
Set pic = ws.Pictures.Paste
pic.Cut
'create email message
On Error Resume Next
With OutMail
.To = Worksheets("Email Template").Range("B1")
.CC = Worksheets("Email Template").Range("B2")
.BCC = ""
.Subject = Worksheets("Email Template").Range("B3")
.Display
Set WordDoc = OutMail.GetInspector.WordEditor
With WordDoc.Range
.PasteAndFormat wdChartPicture
.InsertParagraphAfter
.InsertParagraphAfter
.InsertAfter ""
.InsertParagraphAfter
.InsertAfter ""
End With
.HTMLBody = "" & _
"Good afternoon, <p> Thank you for meeting with me for your monthly 1 on 1! I have included notes to recap your performance. Please feel free to reach out if you have any questions or if there is anything additional needed from me. <p> •<b>Check-in (how are you doing?):</b> Reach out if you have anything you would like to discuss. <p> •<b>Attendance:</b> <p> •Unplanned Absences: <b>XXXXX</b> <p> •PSST Remaining: <b> XXXXXX </b> <p> •PTO: <b>XX as of M/D/YY (2024 EOY projected hours: XX)</b> <p> •<b>Career Development:</b> <p> •XXXXXX <p> •<b>What support do you need from me?</b> <p>•XXXXXXX <p> •<b>Area of focus:</b> XXXXX <p> •XXXX<p> •XXXX<p> •<b>Review of Verint and metrics:</b> <p>" & .HTMLBody
End With
On Error GoTo 0
Set OutApp = Nothing
Set OutMail = Nothing
End Sub
Bonus points if you can get the word "monthly" on the first line to say last month's name instead of "month" (i.e. "Thank you for meeting with for your December 1 on 1" instead of "Thank you for meeting with me for your monthly 1 on 1"), I couldn't figure it out but that's the least of my worries really.
This is what the email currently looks like when it generates:
This is how I would like it to look (or similar):
Here is my code currently:
Sub send_email_with_metrics_as_pic()
Dim OutApp As Object
Dim OutMail As Object
Dim table As Range
Dim pic As Picture
Dim ws As Worksheet
Dim WordDoc
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
'grab table, convert to image, and cut
Set ws = ThisWorkbook.Sheets("Formulas")
Set table = Worksheets("Metrics Dashboard").Range("B6:M28")
ws.Activate
table.Copy
Set pic = ws.Pictures.Paste
pic.Cut
'create email message
On Error Resume Next
With OutMail
.To = Worksheets("Email Template").Range("B1")
.CC = Worksheets("Email Template").Range("B2")
.BCC = ""
.Subject = Worksheets("Email Template").Range("B3")
.Display
Set WordDoc = OutMail.GetInspector.WordEditor
With WordDoc.Range
.PasteAndFormat wdChartPicture
.InsertParagraphAfter
.InsertParagraphAfter
.InsertAfter ""
.InsertParagraphAfter
.InsertAfter ""
End With
.HTMLBody = "" & _
"Good afternoon, <p> Thank you for meeting with me for your monthly 1 on 1! I have included notes to recap your performance. Please feel free to reach out if you have any questions or if there is anything additional needed from me. <p> •<b>Check-in (how are you doing?):</b> Reach out if you have anything you would like to discuss. <p> •<b>Attendance:</b> <p> •Unplanned Absences: <b>XXXXX</b> <p> •PSST Remaining: <b> XXXXXX </b> <p> •PTO: <b>XX as of M/D/YY (2024 EOY projected hours: XX)</b> <p> •<b>Career Development:</b> <p> •XXXXXX <p> •<b>What support do you need from me?</b> <p>•XXXXXXX <p> •<b>Area of focus:</b> XXXXX <p> •XXXX<p> •XXXX<p> •<b>Review of Verint and metrics:</b> <p>" & .HTMLBody
End With
On Error GoTo 0
Set OutApp = Nothing
Set OutMail = Nothing
End Sub