如何解决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

给TA打赏
共{{data.count}}人
人已打赏
未分类

如何在Gitlab Wiki(Markdown)中高亮显示JSON块?

2022-9-8 4:13:31

未分类

带有外键的数据库。描绘前向与后向关系的好方法?

2022-9-8 4:13:33

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索