How to copy Excel pivot charts to an email using PowerShell RRS feed

All replies

  • Use the "Range" "Copy" command on the Chart object you wish to copy.  Outlook MailItems have a "Paste" that will insert the chart at the current location.

    Search for examples.  There are many in C# and some in PowerShell.


    Tuesday, October 15, 2019 8:50 PM
  • Here is the Excel code to copy a chart with data as a picture.

    $wb.Worksheets['Sheet4'].ChartObjects('Chart 2').CopyPicture()


    Tuesday, October 15, 2019 9:27 PM
  • I just saw that you really were asking to copy a Pivot Table and not a chart. This is the command to copy a PT.



    Wednesday, October 16, 2019 3:31 AM
  • Thank you very much, I am unable to get the chart, it is null when pasted to an email any suggestion would be much appreciated!

    $xl = new-object -comobject excel.application 

    $wb = $"PATH.xlsx")
    $ws = $wb.worksheets.item("Sheet1")
    $image = $ws.ChartObjects().copyPicture()
    $chart = $ws.Selection.PasteSpecial()

    Wednesday, October 16, 2019 4:36 AM
  • You have to paste it into a mail item. Open Outlook and create a new mail item in the GUI them run the copy then go to the mail item and use Ctrl-V to paste. This will tell you if you have successfully copied the charts. Your code is not right. You must follow my code exactly or you will get nothing.

    The code you are using cannot copy a pivot table and you must get it by name or you must enumerate the objects in a loop and copy each one individually.

    Using Office automation in this way may be too technical for a non-programmer.  It is not like using PowerShell commands.  You must understand the object models in use.


    Wednesday, October 16, 2019 5:24 AM
  • Got it but it is actually chart is what am trying to copy.
    Wednesday, October 16, 2019 3:40 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,


    Just do it.

    Monday, October 21, 2019 7:56 AM