简体   繁体   English

将 Excel 图表复制/粘贴到 PowerPoint 错误

[英]Copy/paste Excel charts to PowerPoint Error

I am trying to take 60 charts in an Excel workbook and paste them to PowerPoint.我正在尝试在 Excel 工作簿中获取 60 个图表并将它们粘贴到 PowerPoint。 It has been working fine up until we converted to Office 365. Now I am getting an error在我们转换到 Office 365 之前它一直运行良好。现在我收到一个错误

The specified data type is unavailable指定的数据类型不可用

Here is the code:这是代码:

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

It worked great before.以前效果很好。 I have tried ppPasteDefault and ppPasteEnhancedMetafile but they both made the PowerPoint file >30 MB.我尝试过ppPasteDefaultppPasteEnhancedMetafile但它们都使 PowerPoint 文件 > 30 MB。 Before when it worked, it was 3 MB.在它工作之前,它是 3 MB。

Does anyone know why I can't use ppPasteJPG anymore all of the sudden and how to correct the code?有谁知道为什么我突然不能再使用 ppPasteJPG 以及如何更正代码?

If ytou are not using early binding, Excel VBA won't know what ppPasteJPG means.如果你不使用早期绑定,Excel VBA 将不知道 ppPasteJPG 是什么意思。 But ppPasteJPG is merely a named constant with a value of 5. So replace但是 ppPasteJPG 只是一个值为 5 的命名常量。所以替换

PPSlide.Shapes.PasteSpecial DataType:=ppPasteJPG

with

PPSlide.Shapes.PasteSpecial DataType:=5

Got it to work.得到它的工作。 Found that the copy line was not actually copying the Chart for some reason.发现复制行由于某种原因实际上并未复制图表。 Not sure why copy ChartArea works and copy Chart does not though.不知道为什么复制 ChartArea 有效而复制 Chart 却没有。

'ActiveSheet.ChartObjects(chart).chart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
Worksheets(sheet).Activate
ActiveSheet.ChartObjects(chart).Activate
ActiveChart.ChartArea.Copy
' test to see if the clipboard is empty

Set PPSlide = PPPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)

' paste and select the chart picture
PPSlide.Shapes.PasteSpecial DataType:=ppPasteJPG

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM