如何在PowerPoint中用VBA实现删除最后一页幻灯片?

如何在PowerPoint中用VBA实现删除最后一页幻灯片?
2025-03-31 03:40:41
推荐回答(2个)
回答1:

Sub 批量删除第一最后()
Dim ChangedCount As Integer
Dim FileName As String, Mask As String
Dim FindCount As Long
Dim CurPresentation As Presentation
Dim Path As String, FindString As String, ReplaceString As String

Dim oSld As Slide
Dim oShp As Shape
Dim oTxtRng As TextRange
Dim oTmpRng As TextRange

Path = InputBox("请输入路径名称:", "参数输入(1/3)")

If Path = "" Then
MsgBox "参数不能为空!", vbCritical, "出错"
Exit Sub
End If
ChangedCount = 0
FindCount = 0
Mask = "*.ppt"
If Right(Path, 1) <> "\" Then Path = Path & "\"
FileName = Dir(Path & Mask)
On Error Resume Next
Err.Clear
Do Until FileName = ""
DoEvents
Set CurPresentation = Presentations.Open(FileName:=Path & FileName, ReadOnly:=msoFalse, WithWindow:=msoFalse)

For Each oSld In CurPresentation.Slides

CurPresentation.Slides(CurPresentation.Slides.Count).Delete
CurPresentation.Slides(1).Delete

Next oSld
CurPresentation.Save
CurPresentation.Close
FileName = Dir
Loop
MsgBox "处理完毕!"
Close
End Sub

回答2:

Sub DeleteLastSlide()
ActivePresentation.Slides(ActivePresentation.Slides.Count).Delete
End Sub