我正在尝试使用宏将图片放入Powerpoint,作为excel中较大宏的最后一个阶段。
如果我通过PowerPoint VBA下面的代码,它工作正常,但如果我尝试通过Excel(添加引用后)相同的代码我收到此错误消息:
运行时错误''': 对象不支持此属性或方法
我使用的代码是:
Private Sub CommandButton1_Click()
Dim applPP As PowerPoint.Application, prsntPP As PowerPoint.Presentation, TitlePage As PowerPoint.Slide
Set applPP = New PowerPoint.Application
applPP.Visible = True
Set prsntPP = applPP.Presentations.Add
Set TitlePage = prsntPP.Slides.Add(Index:=1, Layout:=ppLayoutTitle)
Dim oSlide As PowerPoint.Slide
Dim oPicture As PowerPoint.Shape
Set oSlide = ActiveWindow.Presentation.Slides(1)
Set oPicture = oSlide.Shapes.AddPicture("C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg", _
msoFalse, msoTrue, 1, 2, 3, 4)
oPicture.ScaleHeight 0.9, msoTrue
oPicture.ScaleWidth 0.9, msoTrue
With ActivePresentation.PageSetup
oPicture.Left = (.SlideWidth \ 2) - (oPicture.Width \ 2)
oPicture.Top = (.SlideHeight \ 2) - (oPicture.Height \ 2)
End With
End Sub
我弹出错误"设置oSlide = ActiveWindow.Presentation.Slides(1)"
任何人都可以向我解释为什么会这样,并建议修复? 谢谢, Btubnfj