我认为您在没有实际创建 Powerpoint.Application 实例的情况下确定变量 oPPTApp 的尺寸。
Public ppApp As PowerPoint.Application
Sub PPTFile()
Dim ppPres As Presentation
Dim fileNameString As String
fileNameString = "C:\testPPT.pptx" '<change to your file path/name
'Create an instance of PPT to work with
Set ppApp = CreateObject("Powerpoint.Application")
ppApp.Visible = True
'Create a new presentation (or you can access an existing file with ppApp.Presentations.Open
Set ppPres = ppApp.Presentations.Add
'Save:
ppPres.SaveAs fileNameString, 1
'Quit the instance of PPT that you initiated above.
ppApp.Quit
End Sub
编辑
当您使用 AddSlide 方法添加幻灯片时,您需要参考CustomLayout
.
Dim sldCount As Integer
sldCount = ppPres.Slides.count
ppPres.Slides.AddSlide sldCount + 1, ppPres.Slides(sldCount).CustomLayout
'Once you've added the slide, then set using Layout:
ppPres.Slides(sldCount + 1).Layout = ppLayoutBlank
或者,您可以使用接受参数的旧.Add
方法,而不是(需要自定义布局):Layout
.AddSlide
ppPres.Slides.Add sldCount + 1, ppLayoutBlank