Excel VBA Macro: Paste Range (Table) As Image In Email Body

Описание к видео Excel VBA Macro: Paste Range (Table) As Image In Email Body

Excel VBA Macro: Paste Range (Table) As Image In Email Body. In this video, we go over how to automatically send an email with a table as a picture in the email message. We select a range of cells to create our table, copy and paste the range as an image, cut and then paste that image in our email body.

Code (YouTube doesn't allow brackets; so LT and GT are used for less than and greater than, respectively):

Sub send_email_with_table_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("Population Data")
Set table = ws.Range("A1:C9")
ws.Activate
table.Copy
Set pic = ws.Pictures.Paste
pic.Cut

'create email message
On Error Resume Next
With OutMail
.to = "[email protected]"
.CC = ""
.BCC = ""
.Subject = "Country Population Data " & Format(Date, "mm-dd-yy")
.Display

Set wordDoc = OutMail.GetInspector.WordEditor
With wordDoc.Range
.PasteandFormat wdChartPicture
.insertParagraphAfter
.insertParagraphAfter
.InsertAfter "Thank you,"
.insertParagraphAfter
.InsertAfter "Greg"
End With

.HTMLBody = "LT BODY style = font-size:11pt; font-family:Calibri GT" & _
"Hi Team, LTpGT Please see table below: LTpGT" & .HTMLBody
End With
On Error GoTo 0

Set OutApp = Nothing
Set OutMail = Nothing

End Sub

Data used in this video:
https://gsociology.icaap.org/datauplo...

#ExcelVBA #ExcelMacro

Комментарии

Информация по комментариям в разработке