VBA_Excel从Excel复制到PPt无法正常工作

时间:2015-12-12 17:48:28

标签: vba excel-vba excel

  Sub ppt2()
     Dim ppapp As PowerPoint.Application
     Dim ppPres As PowerPoint.Presentation
     Set ppapp = New PowerPoint.Application
     ppapp.Visible = True
     ppapp.Activate

    Set ppPres = ppapp.Presentations.Add
    Set ppslide = ppPres.Slides.Add(1, ppLayoutTitle)
    ppslide.Shapes(1).TextFrame.TextRange = "ThisWorkbook"
    Set ppslide = ppPres.Slides.Add(2, ppLayoutBlank)
    ppslide.Select
    Range("A1").Copy
    ppslide.Shapes.Paste
    End Sub

上面的代码ppslide.Shapes.Paste会产生以下错误消息:

  

运行时错误2147188160 shapes.request:无效的请求.CLipboard为空或包含可能未在此处粘贴的数据

1 个答案:

答案 0 :(得分:0)

也许尝试将Range A1中的任何内容放入字符串变量中,然后将其放入Powerpoint中的形状中?

e.g。

myString = Range("A1").text
ppPres.Slides("mySlide").Shapes("myShape").TextFrame.TextRange = myString