We help IT Professionals succeed at work.
Get Started

Copy chart to email and send to list based on cell values

Last Modified: 2019-12-30
Daily-Call-Metrics---By-Campaign_Ne.xlsmI am trying to email a pivot table to a list of email addresses on an excel sheet. I have tried multiple ways to accomplish this but no success. Currently I can create the pivot table as a chart on a new sheet and open a new email. However, the list of email addresses will not appear in the "TO" field and the chart will not copy to the email. I am open to new ways of accomplishing this. Creating a new worksheet with the pivot table converted to a chart was just the only way I could figure out to do it. Ideally I would not have to create a new worksheet that I have to close when done. I will attached the worksheet. Here is what I have so far:

Sub FLSnapShot()

Dim RNG As Range
Set RNG = Range("A1:U26")
Dim sdate As String
Dim FileName As String
Dim SavePath As String
Dim SaveAs As String

sdate = Format(Sheets("Florida").Range("W1"), "MM-DD-YYYY")
FileName = "Daily Call Stats "
SaveAs = FileName & sdate & ".png"
SavePath = "N:\WFM\Snapshots\"

'''build the chart

Dim CH As Chart
Set CH = Charts.Add
CH.Location xlLocationAsObject, "SHEET1"
Set CH = ActiveChart
RNG.CopyPicture xlScreen, xlBitmap
CH.Export (SavePath & SaveAs)
CH.Parent.Name = "DS"
ActiveSheet.ChartObjects("DS").Height = RNG.Height
ActiveSheet.ChartObjects("DS").Width = RNG.Width

''''sending in outlook

Dim o As Outlook.Application
Set o = New Outlook.Application
Dim wks As Worksheet
Set wks = Worksheets("Sheet1")

On Error Resume Next

For I = 2 To wks.Range("W" & Rows.Count).End(xlUp).Row
Dim omail As Outlook.MailItem
Set omail = o.CreateItem(olMailItem)

With omail
.To = wks.Range("W" & I).Value
.Subject = "Daily Call Stats"
.HTMLBody = "Hello," & "<br>" & "<br>" & "Here is the daily dashboard:" & "<br>" & "<br>" & "<img src = SavePath & SaveAs />"

End With
On Error GoTo 0

Set omail = Nothing
Next I
Set o = Nothing

End Sub
Watch Question
Mechanical Engineer
Most Valuable Expert 2013
Distinguished Expert 2020
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE