粘贴Bitmap时出现Shapes.PasteSpecial:Invalid request如何解决?

How to solve a Shapes.PasteSpecial:Invalid request when pasting Bitmap?

我正在尝试创建一个 VBA 例程来从 excel 复制一些表格并将它们作为位图粘贴到我的 PowerPoint 演示文稿中。 我尝试了不同的方法,但我一直收到此错误:Shapes.PasteSpecial:无效请求。指定的数据类型不可用。 我不确定如何解决它,因为对于某些幻灯片,代码似乎可以工作,而对于其他幻灯片,则没有。 目前代码如下:

Set PowerPointApp = CreateObject("Powerpoint.application")
DestinationPPT = ("C:xxxxx.pptx")
PowerPointApp.Presentations.Open (DestinationPPT)
Set myPresentation = PowerPointApp.ActivePresentation
Set ArquivoAberto = ActiveWorkbook
Set mySlide = Nothing
Set myShape = Nothing

Final = 142
j = 5

For i = 9 To Final

Set mySlide = Nothing
Set myShape = Nothing
ArquivoAberto.Sheets("B. Metrics On").Range(Cells(i, 2), Cells(i + 6, 8)).Select
Selection.Copy

Set mySlide = myPresentation.Slides(j)
    mySlide.Shapes.PasteSpecial DataType:=1

Selection.Clear

Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
        myShape.Name = "CashOn"
j = j + 1
i = i + 6

Next

Set ArquivoAberto = Nothing

End Sub

如有任何帮助,我们将不胜感激。

我无法重现您的错误。 在我的电脑上运行良好:/ 我认为发生这种情况时剪贴板是空的。 复制后尝试使用 DoEvents 编写代码。 也许这会奏效:

Set PowerPointApp = CreateObject("Powerpoint.application")
DestinationPPT = ("C:xxxxx.pptx")
PowerPointApp.Presentations.Open (DestinationPPT)
Set myPresentation = PowerPointApp.ActivePresentation
Set ArquivoAberto = ActiveWorkbook
Set mySlide = Nothing
Set myShape = Nothing

Final = 142
j = 5

For i = 9 To Final

Set mySlide = Nothing
Set myShape = Nothing
ArquivoAberto.Sheets("B. Metrics On").Range(Cells(i, 2), Cells(i + 6, 8)).Select
Selection.CopyPicture xlScreen, xlBitmap
DoEvents

Set mySlide = myPresentation.Slides(j)
    mySlide.Shapes.PasteSpecial DataType:=1
DoEvents
Application.CutCopyMode = False

Selection.Clear

Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
        myShape.Name = "CashOn"
j = j + 1
i = i + 6

Next

Set ArquivoAberto = Nothing

End Sub