none
Copy excel chart using SendKeys? RRS feed

  • Question

  • Hi, I've found that in Excel 2010, the .Copy method for copying a chart is not the same as manually copying the chart using CTRL-C. Specifically, when pasting the chart into PPT 2010, the .Copy method does not allow pasting with an embedded workbook (only a linked workbook).

    As I require an embedded workbook, I am trying a work around where I copy and paste the chart using SendKeys. The pasting part works well -- but as of yet I can't manage to copy the chart using SendKeys ... instead, it seems to copy the last line of VBA code (since that's probably the active window). Here is the code:

    wrkbk.Activate
        wrksht.ChartObjects("Chart 1").Select
        SendKeys ctrlC
        'SendKeys "^{C}"
        objPPT.Activate
        
        AppActivate ("Microsoft Powerpoint")
        objPPT.ActiveWindow.Selection.Unselect
        SendKeys "+{F10}"
        SendKeys "K"

    Thanks

    John

    • Moved by Kee Poppy Sunday, January 16, 2011 9:57 AM (From:Visual Basic General)
    Thursday, January 13, 2011 5:29 PM

Answers

  • Here is part of some code that I use in a Word Add-in to copy charts from Excel and Paste them into a Word document
                    xlchart.CopyPicture Appearance:=1, Format:=-4147
                   bmChart = "Q" & q
                   MainDoc.Bookmarks(bmChart).Range.PasteSpecial DataType:=wdPasteEnhancedMetafile

    In your case, try something like

    wrkbk.Activate
       wrksht.ChartObjects("Chart 1").CopyPicture Appearance:=1, Format:=-4147
       objPPT.Activate
       AppActivate ("Microsoft Powerpoint")
       objPPT.ActiveWindow.Selection.PasteSpecial DataType:=wdPasteEnhancedMetafile


    Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "John Affleck" wrote in message news:2682cd25-729d-41a9-8aa3-036593d0b5a0@communitybridge.codeplex.com...

    Hi, I've found that in Excel 2010, the .Copy method for copying a chart is not the same as manually copying the chart using CTRL-C. Specifically, when pasting the chart into PPT 2010, the .Copy method does not allow pasting with an embedded workbook (only a linked workbook).

    As I require an embedded workbook, I am trying a work around where I copy and paste the chart using SendKeys. The pasting part works well -- but as of yet I can't manage to copy the chart using SendKeys ... instead, it seems to copy the last line of VBA code (since that's probably the active window). Here is the code:

    wrkbk.Activate
        wrksht.ChartObjects("Chart 1").Select
        SendKeys ctrlC
        'SendKeys "^{C}"
        objPPT.Activate

        AppActivate ("Microsoft Powerpoint")
        objPPT.ActiveWindow.Selection.Unselect
        SendKeys "+{F10}"
        SendKeys "K"

    Thanks

    John


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    • Proposed as answer by Bruce Song Tuesday, January 18, 2011 3:52 AM
    • Marked as answer by Bruce Song Friday, January 21, 2011 8:40 AM
    Sunday, January 16, 2011 11:40 AM
    Moderator

All replies

  • Here is part of some code that I use in a Word Add-in to copy charts from Excel and Paste them into a Word document
                    xlchart.CopyPicture Appearance:=1, Format:=-4147
                   bmChart = "Q" & q
                   MainDoc.Bookmarks(bmChart).Range.PasteSpecial DataType:=wdPasteEnhancedMetafile

    In your case, try something like

    wrkbk.Activate
       wrksht.ChartObjects("Chart 1").CopyPicture Appearance:=1, Format:=-4147
       objPPT.Activate
       AppActivate ("Microsoft Powerpoint")
       objPPT.ActiveWindow.Selection.PasteSpecial DataType:=wdPasteEnhancedMetafile


    Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "John Affleck" wrote in message news:2682cd25-729d-41a9-8aa3-036593d0b5a0@communitybridge.codeplex.com...

    Hi, I've found that in Excel 2010, the .Copy method for copying a chart is not the same as manually copying the chart using CTRL-C. Specifically, when pasting the chart into PPT 2010, the .Copy method does not allow pasting with an embedded workbook (only a linked workbook).

    As I require an embedded workbook, I am trying a work around where I copy and paste the chart using SendKeys. The pasting part works well -- but as of yet I can't manage to copy the chart using SendKeys ... instead, it seems to copy the last line of VBA code (since that's probably the active window). Here is the code:

    wrkbk.Activate
        wrksht.ChartObjects("Chart 1").Select
        SendKeys ctrlC
        'SendKeys "^{C}"
        objPPT.Activate

        AppActivate ("Microsoft Powerpoint")
        objPPT.ActiveWindow.Selection.Unselect
        SendKeys "+{F10}"
        SendKeys "K"

    Thanks

    John


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    • Proposed as answer by Bruce Song Tuesday, January 18, 2011 3:52 AM
    • Marked as answer by Bruce Song Friday, January 21, 2011 8:40 AM
    Sunday, January 16, 2011 11:40 AM
    Moderator
  • Hi Doug,

    is it possible to copy multiple charts in one word document using your logic of merging charts with word??

    Thanks

    Ankit

    Thursday, June 14, 2012 6:18 PM