如何禁用复制chartarea中的形状?

时间:2017-08-29 18:30:35

标签: excel excel-vba excel-formula shapes vba

我在Excel中有一个图表,我的宏在图表区域的右侧填充了10个形状。我想只将图表复制到电源点,到目前为止无法找到禁用复制形状的方法。如果我复制图表,它也会复制形状。

1 个答案:

答案 0 :(得分:1)

这是一个快速示例,它从活动工作表复制第一个图表,将其粘贴到活动演示文稿的第一张幻灯片,并从粘贴的图表中删除任何现有形状...

'Declare Excel variables
Dim ChartObj As ChartObject

'Declare PowerPoint variables
Dim ppApp As Object
Dim ppPres As Object
Dim ppChartObj As Object
Dim ppShape As Object

'Copy first chart from active sheet
Set ChartObj = ActiveSheet.ChartObjects(1)
ChartObj.Copy

'Paste chart into first slide of active presentation
Set ppApp = GetObject(, "PowerPoint.Application")
Set ppPres = ppApp.ActivePresentation
Set ppChartObj = ppPres.slides(1).Shapes.Paste(1)

'Delete shapes from chart
For Each ppShape In ppChartObj.Chart.Shapes
    ppShape.Delete
Next ppShape

希望这有帮助!