如何解决Shapes.PasteSpecial:无效请求时粘贴位图?

我试图创建一个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

本文来自投稿,不代表运维实战侠立场,如若转载,请注明出处:https://www.shizhanxia.com/690.html

(0)
上一篇 2022年6月29日 下午3:59
下一篇 2022年6月29日 下午3:59

相关推荐

发表评论

登录后才能评论