我使用EXcel VBA通过自动脚本将数据从excel传输到powerpoint幻灯片。我试图复制excel工作表的usedrange,然后将其粘贴为幻灯片中的图像,然后从第四张幻灯片的模板中添加新幻灯片并将其余工作表复制到下一张幻灯片。从VBA excel复制到powerpoint
这我目前使用越来越以下错误“对象变量或与块变量未设置”代码
任何人都可以建议我在下面的代码。
希望对此有清楚的解释。如果不是,请询问更多解释。
感谢
Private Sub CommandButton2_Click()
Dim PP As PowerPoint.Application
Dim PPpres As PowerPoint.Presentation
Dim PPslide As Object
Dim PpShape As PowerPoint.Shape
Dim SlideTitle As String
Dim SlideNum As Integer
Dim WSrow As Long
Dim Sh As Shape
Dim Rng As Range
Dim myshape As Object
'Open PowerPoint and create new presentation
Set PP = GetObject(class, "PowerPoint.Application")
PP.Visible = True
PP.Presentations.Open FileName:=("\\C:\Users\Templates)"
'Specify the chart to copy and copy it
For Each WS In Worksheets
If (WS.Name) <> "EOS" Then
ThisWorkbook.Worksheets(WS.Name).Activate
ThisWorkbook.ActiveSheet.UsedRange.CopyPicture
'pSlide.Shapes.Paste
'Copy Range from Excel
Set Rng = ThisWorkbook.ActiveSheet.Range("A1:I8")
'Copy Excel Range
Rng.Copy
'Set PPslide = PPpres.Slides.Add(5, 33)
PP.ActiveWindow.View.GotoSlide (4)
Set PPslide = PPpres.Slides(4).Shapes.Paste
'Paste to PowerPoint and position
PPslide.Shapes.PasteSpecial DataType:=2 '2 = ppPasteEnhancedMetafile
Set myshape = PPslide.Shapes(PPslide.Shapes.Count)
'Set position:
myshape.Left = 66
myshape.Top = 152
End If
Next
'Make PowerPoint Visible and Active
PowerPointApp.Visible = True
PowerPointApp.Activate
'Clear The Clipboard
Application.CutCopyMode = Falseenter code here`
End Sub
通过固定压痕所以它是格式化代码,请正确格式的代码,并删除双行距:) – samiles
并说这行的错误。 – SJR
嗨,谢谢你的回复。 从这一行设置PPslide = PPpres.Slides(4).Shapes.Paste 我收到错误为“öbject变量或块变量未设置”。在打开Powerpoint的模板 之后,excel工作表的范围是复制,但它不粘贴在特定的幻灯片(如上所述的第4张幻灯片)中。 –