我需要从 Excel 工作表中获取范围,并在此代码中使用它来将其复制并粘贴到 Powerpoint 演示文稿上。我认为该范围不再像以前那样工作了,但我不知道有什么其他方法可以做到这一点,有什么建议吗?
Sub PPTableMacro()
Dim oPPTApp As PowerPoint.Application
Dim oPPTShape As PowerPoint.Shape
Dim oPPTFile As PowerPoint.Presentation
Dim SlideNum As Integer
Dim strPresPath As String, strExcelFilePath As String, strNewPresPath As String
strPresPath = "filepath"
strNewPresPath = "filepath"
Set oPPTApp = CreateObject("PowerPoint.Application")
oPPTApp.Visible = msoTrue
Set oPPTFile = oPPTApp.Presentations.Open(strPresPath)
SlideNum = 1
oPPTFile.Slides(SlideNum).Select
'Set oPPTShape = oPPTFile.Slides(SlideNum).Shapes("ws22")
Set ws = ThisWorkbook.Sheets("SHEET")
Set Table = ThisWorkbook.Sheets("SHEET").range("A2:A15,D2:D15,J2:J15,L2:L15,R2:R15")
Table.CopyPicture xlPrinter, xlPicture '<------ERROR HERE!
'SlideNum = SlideNum + 1
oPPTFile.Slides(1).Shapes.PasteSpecial (ppPastePicture)
oPPTFile.Slides(SlideNum).Select
End Sub
正如 Shortter 在评论中指出的那样,如果尚未添加对 Excel 模型的引用,则需要使用 Excel const xlPrinter 和 xlPicture 值。
Range("A2:A15,D2:D15,J2:J15,L2:L15,R2:R15").CopyPicture xlPrinter, xlPicture
我在 Excel 中快速测试表明
Range.CopyPicture
不适用于多项选择。
我会向 Excel 文件添加另一个工作表,并将数据收集到单个连续(连接)单元格中。