以下のコードでは、PowerPointにレイトバインディングを使用しているので、PowerPointインスタンスが開いているかどうかを確認します(PowerPointライブラリへの参照を追加する必要はありません)。
その後、ActivePresentation
をppPres
に設定します。
最後に、2番目のスライド(最初のスライドだけが残ります)まですべてのスライドを最後から後ろに削除するようにループします。
注:For i = ppPres.Slides.Count To 2 Step -1
ループを必要に応じて簡単に変更できます。
コード
Option Explicit
Sub DEL()
Dim ppProgram As Object
Dim ppPres As Object
Dim ppSlide As Object
Dim i As Long
On Error Resume Next
Set ppProgram = GetObject(, "PowerPoint.Application")
On Error GoTo 0
' check if PowerPoint instance is open >> if not raise an error
If ppProgram Is Nothing Then
MsgBox "PowerPoint is closed!"
Exit Sub
Else
' set the ppPres object to active PowerPoint presentation
Set ppPres = ppProgram.ActivePresentation
' always loop backwards when deleting objects (in this case slides)
For i = ppPres.Slides.Count To 2 Step -1
Set ppSlide = ppPres.Slides(i)
ppSlide.Delete
Next i
End If
End Sub
エラーとは何ですか? –
質問を投稿する前にstackoverflowを検索してください。 –