使用vba从excel创build多个PPT

我想用vbamacros创build多个PPT文件。

考虑这种情况,已经打开了PPT应用程序。 当我运行macros,它应该创build一个新的单独的PPT应用程序,但是,我的macros追加幻灯片打开文件。

如何创build一个单独的PPT应用程序,并做其余的事情。

谢谢,下面是代码的一部分。

Dim newPowerPoint As Object 'PowerPoint.Application ' Dim activeSlide As Object 'PowerPoint.Slide Dim sht As Worksheet On Error Resume Next Set newPowerPoint = CreateObject("PowerPoint.Application") 'If newPowerPoint Is Nothing Then 'Set newPowerPoint = New PowerPoint.Application 'End If If newPowerPoint.Presentations.Count = 0 Then newPowerPoint.Presentations.Add End If 'Show the PowerPoint newPowerPoint.Visible = True For Each sht In ActiveWorkbook.Sheets newPowerPoint.ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count + 1, ppLayoutText newPowerPoint.ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count) activeSlide.Shapes(1).Delete activeSlide.Shapes(1).Delete Range("A1:T32").Select Selection.Copy activeSlide.Shapes.PasteSpecial(DataType:=ppPasteEnhancedMetafile).Select 

你不想创build一个新的PPT应用程序,你需要的是一个新的PPT演示文稿,然后添加幻灯片。 最简单的方法是为演示文稿添加一个variables(即Dim PPPres As Powerpoint.Presentation ),然后将新的幻灯片添加到该演示文稿

编辑:包括我用于初始化PPT演示文稿的代码版本:

 Dim PPApp As PowerPoint.Application Dim PPPres As PowerPoint.Presentation Dim PPSlide As PowerPoint.Slide 'Open PPT if not running, otherwise select active instance On Error Resume Next Set PPApp = GetObject(, "PowerPoint.Application") If PPApp Is Nothing Then 'Open PowerPoint Set PPApp = CreateObject("PowerPoint.Application") PPApp.Visible = True End If On Error GoTo ErrHandler 'Generate new Presentation and slide for graphic creation Set PPPres = PPApp.Presentations.Add Set PPSlide = PPPres.Slides.Add(1, ppLayoutBlank) PPApp.ActiveWindow.ViewType = ppViewSlide PPPres.PageSetup.SlideSize = ppSlideSizeOnScreen PPApp.ActiveWindow.WindowState = ppWindowMaximized