在保持源格式的同时将图表复制到powerpoint

时间:2015-08-11 06:00:30

标签: excel vba excel-vba powerpoint powerpoint-vba

我有一张包含饼图的Excel工作表,我想将其复制到PowerPoint幻灯片(幻灯片编号10)。

我还想保持源格式在哪里通过如果我在饼图中进行任何格式更改 它应该在幻灯片中修改< /强>

这有什么vba编码吗?遇到这个代码,但它似乎对我不起作用。

'copy the chart from Excel
        xlSheet.ChartObjects(ChartName).Select
        xlSheet.ChartObjects(ChartName).Copy
    'Select Slide
        Set mySlide = myPresentation.Slides(Charts(r).SlideName)
        mySlide.Select
    'stall to make sure the slide is selected
        For k = 1 To 1000
            DoEvents
        Next k
    'paste on selected slide
        PPApp.CommandBars.ExecuteMso ("PasteSourceFormatting")
        PPApp.CommandBars.ReleaseFocus
    'sit and wait for changes to be made
        For k = 1 To 5000
            DoEvents
        Next k

2 个答案:

答案 0 :(得分:0)

我通常使用这样的PasteSpecial方法:

xlSheet.Charts(ChartName).ChartArea.Copy

Set mySlide = myPresentation.Slides(Charts(r).SlideName)

'Use paste special method
mySlide.Shapes.PasteSpecial DataType:=ppPasteEnhancedMetafile, Link:=msoTrue

mySlide.Shapes.Title.TextFrame.TextRange.Text = "Chart Title"

'Free the Object variable
Set mySlide = Nothing

答案 1 :(得分:0)

您也可以使用2010年以后的CommandBars方法,尽管它意味着在视图中激活PowerPoint窗口并激活:

With ActivePresentation
  .Windows(1).Activate
  .Windows(1).View.GotoSlide (1)
  .Application.CommandBars.ExecuteMso ("PasteSourceFormatting") ' From 2010 only
  .Application.CommandBars.ReleaseFocus
End With