Insert PivotTable (in Email Body) | Excel VBA Macro

Published: 11 March 2024
on channel: greggowaffles
980
26

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


Watch video Insert PivotTable (in Email Body) | Excel VBA Macro online without registration, duration hours minute second in high quality. This video was added by user greggowaffles 11 March 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 98 once and liked it 2 people.