我有一个宏,可以将 Excel 表中的所有图表复制到新的 PowerPoint 文件中。
问题是,如果我在 Excel 文件打开时使用过滤器,图表会自动更新。为了防止这种情况,我可以使用Ctrl+u并嵌入它。但我不知道如何更改我的代码来执行相同的操作(目前代码只是“复制”它)
有人知道使用特殊副本的正确形式吗?
Sub ChartObjectsPowerpoint()
Dim pptApp As Object, pptPres As Object
Dim chtObj As Object, shp As Object, i
Set pptApp = CreateObject("PowerPoint.Application")
Set pptPres = pptApp.Presentations.Add(msoTrue)
For Each chtObj In ActiveSheet.ChartObjects
chtObj.Chart.ChartArea.Copy
i = i + 1
Set PPTSlide = pptPres.Slides.Add(i, 12) '12 = ppLayoutBlank
Set shp = PPTSlide.Shapes.Paste
shp.Top = 0
shp.Left = 0
shp.Width = 800
shp.Height = 400
Next
pptApp.Visible = True
End Sub
答案1
要断开从 Excel 复制到 PowerPoint 的图表之间的链接,可以使用以下代码电子表格大师:
Sub BreakAllExcelLinks()
'PURPOSE: Break any external links in your PowerPoint presentation
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault
Dim shp As Shape
Dim sld As Slide
'Loop Through Each Slide in ActivePresentation
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
On Error Resume Next
shp.LinkFormat.BreakLink
On Error GoTo 0
Next shp
Next sld
End Sub
它将阻止图表自我更新。