感谢BigBen-以下代码已纠正了一个示例,该示例显示了如何清除现有Powerpoint中的幻灯片,然后将粘贴范围从excel到Powerpoint粘贴为图片。最初的错误是关于未定义单元格的问题,然后围绕直线进行操作以在Powerpoint中定义形状。该代码应该正常工作。
Option Explicit
Sub ExportToPPT()
Dim ppApp As PowerPoint.Application
Set ppApp = New PowerPoint.Application
Dim ppFileName As String
ppFileName = "C:\Users\Desktop\Financial Summary.pptx"
Dim ppPres As PowerPoint.Presentation
Set ppPres = ppApp.Presentations.Open(filename:=ppFileName)
Dim ppSlide As PowerPoint.Slide
Dim i As Integer
For i = 2 To 9
Set ppSlide = ppPres.Slides(i)
Dim j As Integer
For j = ppSlide.Shapes.Count To 1 Step -1
If ppSlide.Shapes(j).Type = msoPicture Then
ppSlide.Shapes(j).Delete
End If
Next j
Next i
'preparation of the export
Dim lastrow As Long
Dim lRow As Long
Dim lCol As Long
Workbooks("A.xlsm").Activate
Sheets("Graph Data").Select
Range("E4").Value = "8"
Application.Calculate
`Set Sel = Selection
Set source = ActiveWorkbook.Sheets("waterfall").Range("B1")
ActiveWorkbook.Sheets("waterfall").Range("D1:AE40").Copy
Set ppSlide = ppPres.Slides(9)
ppSlide.Shapes.PasteSpecial ppPasteBitmap
End Sub