VBA Outlook email

Amo840812

New Member
Joined
Sep 5, 2024
Messages
8
Office Version
  1. 365
Platform
  1. Windows
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:

1739563144507.png



This is how I would like it to look (or similar):

1739563177776.png


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> &bull;<b>Check-in (how are you doing?):</b> Reach out if you have anything you would like to discuss. <p> &bull;<b>Attendance:</b> <p> &bull;Unplanned Absences: <b>XXXXX</b> <p> &bull;PSST Remaining: <b> XXXXXX </b> <p> &bull;PTO: <b>XX as of M/D/YY (2024 EOY projected hours: XX)</b> <p> &bull;<b>Career Development:</b> <p> &bull;XXXXXX <p> &bull;<b>What support do you need from me?</b> <p>&bull;XXXXXXX <p> &bull;<b>Area of focus:</b> XXXXX <p> &bull;XXXX<p> &bull;XXXX<p> &bull;<b>Review of Verint and metrics:</b> <p>" & .HTMLBody
End With
On Error GoTo 0

Set OutApp = Nothing
Set OutMail = Nothing

End Sub
 
For the month:
VBA Code:
"Good afternoon, <p>Thank you for meeting with me for your " & Format(DateSerial(Year(Date), Month(Date) - 1, 1), "Mmmm") & " 1 on 1! etc."

For the formatting, use an online HTML editor such as Online HTML Editing and Cleaner to format the bullet list as you require and copy the generated HTML into your code.
 
Upvote 0

Forum statistics

Threads
1,226,771
Messages
6,192,926
Members
453,767
Latest member
922aloose

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