1
我想使用vba宏创建多个PPT文件。使用vba从excel创建多个PPT
考虑这种情况,已经打开PPT应用程序。 当我运行宏时,它应该创建一个新的单独的PPT应用程序,但是,我的宏在打开的文件上追加了幻灯片。
如何创建一个单独的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
你也应该重置对象后的错误处理程序(并使用get对象调用) – RGA
感谢它的工作原理 – Singaravelan