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