【发布时间】:2015-10-22 20:47:29
【问题描述】:
我想使用 VBA(Excel 和 PowerPoint 2013)将多个图表复制粘贴到 PowerPoint。只要我不尝试破坏 Excel 和 PowerPoint 之间的图形连接,我的下面的宏就可以正常工作 - 我绝对需要这样做。
我在 Google 上进行了查找,发现有人建议使用 .Breaklink 方法:只要我的工作表上不超过一个图表,它的效果非常好,实际上会断开链接。如果至少有两个图表,它将正确复制第一个图表,然后在处理第二个图表时抛出“MS PowerPoint 已停止工作”消息。
我应该如何进行?
我尝试在 .Chart.ChartData 和 .Shape 对象上应用 .BreakLink 方法,但无济于事。
Sub WhyIsThisWrong()
Application.ScreenUpdating = False
Dim aPPT As PowerPoint.Application
Dim oSld As PowerPoint.Slide
Dim oShp As PowerPoint.Shape
Dim oCh As ChartObject
Set aPPT = New PowerPoint.Application
aPPT.Presentations.Add
aPPT.Visible = True
For Each oCh In ActiveSheet.ChartObjects
oCh.Activate
ActiveChart.ChartArea.Copy
aPPT.ActivePresentation.Slides.Add aPPT.ActivePresentation.Slides.Count + 1, ppLayoutText
Set oSld = aPPT.ActivePresentation.Slides(aPPT.ActivePresentation.Slides.Count)
oSld.Shapes.PasteSpecial(DataType:=ppPasteDefault).Select
'Something is wrong here
With oSld.Shapes(3)
If .Chart.ChartData.IsLinked Then
'.Chart.ChartData.BreakLink
.LinkFormat.BreakLink
End If
End With
Next oCh
Set oSld = Nothing
Set aPPT = Nothing
Application.ScreenUpdating = True
End Sub
【问题讨论】:
标签: vba excel powerpoint