|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
由于PPT2003到PPT2007微软设计思路不同,代码无法做到兼顾,只好分开。PPT2010遇到的错误已完善,经自己测试可以正常运行。
PPT2003 删除任何幻灯片都不使用的母版,代码如下:
Option Explicit
Sub ModifyDesign()
Dim oSlide As Slide
Dim Dic As Object, i As Long
Set Dic = CreateObject("Scripting.Dictionary")
For Each oSlide In ActivePresentation.Slides
Dic(oSlide.Design.Index) = ""
Next oSlide
For i = ActivePresentation.Designs.Count To 1 Step -1
If Not Dic.exists(i) Then ActivePresentation.Designs(i).Delete
Next i
Set Dic = Nothing
End Sub
PPT2007/2010 删除任何幻灯片都不使用的母版和版式,代码如下:(备注:PPT2010以上的未测试过,欢迎大家测试告知结果)
Option Explicit
Sub DeleteUnusedMaster()
Dim oSlide As Slide
Dim Dic As Object, i As Long, j As Long
Dim oDicItem As Variant, DicItem As Variant
Dim oFlag As Boolean
Set Dic = CreateObject("Scripting.Dictionary")
'获得幻灯片母版编号和版式名称
For Each oSlide In ActivePresentation.Slides
Dic(oSlide.Design.Index) = Dic(oSlide.Design.Index) & "," & oSlide.CustomLayout.Name
Next oSlide
'删除任何幻灯片都不使用母版和版式
For i = ActivePresentation.Designs.Count To 1 Step -1
With ActivePresentation.Designs(i)
If Not Dic.exists(i) Then
.Delete
Else
DicItem = Split(Right(Dic(i), Len(Dic(i)) - 1), ",")
For j = .SlideMaster.CustomLayouts.Count To 1 Step -1
oFlag = False
For Each oDicItem In DicItem
If oDicItem = .SlideMaster.CustomLayouts(j).Name Then oFlag = True
Next oDicItem
If oFlag = False Then .SlideMaster.CustomLayouts(j).Delete
Next j
End If
End With
Next i
Set Dic = Nothing
End Sub
|
|