Insert PivotTable (in Email Body) | Excel VBA Macro

Описание к видео Insert PivotTable (in Email Body) | Excel VBA Macro

Excel VBA Macro: Insert PivotTable (in Email Body)

💥Subscribe:    / @greggowaffles  

Code:
Sub send_email_with_pivot_table()

Dim OutApp As Object
Dim OutMail As Object
Dim table As PivotTable
Dim pic As Picture
Dim ws As Worksheet
Dim wordDoc

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

Set ws = ThisWorkbook.Sheets("Pivot Sheet")
Set table = ws.PivotTables("PivotTable1")

ws.Activate
table.TableRange2.Copy

Set pic = ws.Pictures.Paste

With pic
.Select
.Cut
End With

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

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

.HTMLBody = "<Body style = font-size: 12pt; font-family: Arial> " & _
"Hi Team, <p> Please see table below: <p> " & .HTMLBody
End With
On Error GoTo 0

Set OutApp = Nothing
Set OutMail = Nothing


End Sub

#excelmacro #excelvba

Комментарии

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