【发布时间】:2020-12-21 16:23:48
【问题描述】:
我正在尝试在 Excel 工作簿中获取 60 个图表并将它们粘贴到 PowerPoint。在我们转换为 Office 365 之前,它一直运行良好。现在我收到一个错误
指定的数据类型不可用
代码如下:
copy_chart "318Pivot", "cht404_318", 3
Public Function copy_chart(sheet, chart, slide)
Dim oshp As Shape
Dim PPApp As Object
Dim PPPres As Object
Dim PPSlide As Object
Dim PPShape As Object
Set PPApp = GetObject(, "Powerpoint.Application")
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
PPApp.ActiveWindow.View.GotoSlide (slide)
Worksheets(sheet).Activate
ActiveSheet.ChartObjects(chart).chart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
Set PPSlide = PPPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
' paste and select the chart picture
PPSlide.Shapes.PasteSpecial DataType:=ppPasteJPG '**This is where it errors out**
'With PPShape
For j = 1 To PPSlide.Shapes.Count
With PPSlide.Shapes(j)
If .Type = msoPicture Then
.LockAspectRatio = False
.Height = 5# * 72
.Width = 10# * 72
.Left = 0# * 72
.Top = 1.5 * 72
End If
End With
Next j
DoEvents
' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
Set PPShape = Nothing
End Function
以前效果很好。我尝试过ppPasteDefault 和ppPasteEnhancedMetafile,但它们都使 PowerPoint 文件 >30 MB。在它工作之前,它是 3 MB。
有谁知道为什么我突然不能再使用 ppPasteJPG 以及如何更正代码?
【问题讨论】:
-
ppPastePNG呢? -
尝试单步调试代码,看看是否会产生同样的错误。
-
ppPastePNG 并单步执行代码给了我相同的结果。快把我逼疯了!!
标签: excel vba charts powerpoint