我有一组自定义布局,它们是我认可的企业标准。有 1 个主布局和 11 个自定义布局。
因为用户可能会粘贴旧内容,所以我知道他们粘贴的任何幻灯片都会带来相应的布局。编写一个按钮以删除任何不属于已批准集的自定义布局的最佳方法是什么?
我拥有的代码如下,但它给了我一个错误,上面写着“幻灯片(未知成员):无效请求。无法删除主人。”
任何帮助都感激不尽!
Dim oDesign As design
For Each oDesign In ActivePresentation.Designs
'if design name is CC standard then
If oDesign.Name = CCSMNAME$ Then
Dim oLayout As CustomLayout
'Check the name of each layout against the permitted set, delete any that are additional
For Each oLayout In oDesign.SlideMaster.CustomLayouts
If oLayout.Name <> "Title Slide (Basic)" Or oLayout.Name <> "Title Slide (Standard Stock Image)" Or oLayout.Name <> "Title Slide (Image - Right)" Or oLayout.Name <> "Agenda" Or oLayout.Name <> "Body/Content (Basic)" Or oLayout.Name <> "Report (Approval and Disclaimer)" Or oLayout.Name <> "Report Body/Content" Or oLayout.Name <> "Divider" Or oLayout.Name <> "Quals (Basic -Right)" Or oLayout.Name <> "Quals (Basic - Left)" Or oLayout.Name <> "Content and Closing" Then
oLayout.Delete
End If
Next oLayout
Else
'Else, the Design found is not the CC Master so delete it
'(This runs for all remaining masters)
oDesign.Delete
End If
Next oDesign
我现在正在使用以下代码 - 有谁知道为什么不是删除所有其他幻灯片母版,而是只删除序列中的下一个然后退出?
子清理模板()
'Declare some variables
Dim oDesign As design
Dim oDesigns As Designs
Dim oLayout As CustomLayout
Dim masterCount As Long
Dim layoutCount As Long
Dim strInUse As String
On Error Resume Next
For Each oDesign In ActivePresentation.Designs
If oDesign.Name = CCSMNAME$ Then
MsgBox "The script has found " & oDesign.SlideMaster.CustomLayouts.Count & " layouts in the CC Master. There should be 11 in total. An integrity check will now run to remove any non-approved slide layouts."
'Loop through set backwards to keep integrity of data set when deleting
For layoutCount = oDesign.SlideMaster.CustomLayouts.Count To 1 Step -1
Set oLayout = oDesign.SlideMaster.CustomLayouts(layoutCount)
Err.Clear
'Check the name of each layout against the permitted set, delete any that are additional
If checkAllowed(oLayout) = False Then
oLayout.Delete
End If
If Err <> 0 Then
strInUse = strInUse & oLayout.Name & " , "
End If
Next layoutCount
MsgBox ("Any additional layouts deleted, cleanup of CC Master completed.")
Else
'Else, a Slide Master has been found that is not the CC Master so delete it
MsgBox ("An additional Slide Master named " & oDesign.Name & " that is not CC approved has been detected. It is not in use, so it will be removed.")
oDesign.Delete
End If
Next oDesign
'Alert the user to any foreign slide designs found that couldn't be deleted
If Len(strInUse) > 0 Then
MsgBox "The following slide designs seem to be either in use, or protected: " & Left(strInUse, Len(strInUse) - 1)
End If
结束子
函数 checkAllowed(olay As CustomLayout) As Boolean
Select Case olay.Name
Case Is = "Title Slide (Basic)", _
"Title Slide (Image - Right)", _
"Title Slide (Standard Stock Image)", _
"Agenda", "Body/Content (Basic)", _
"Report (Approval and Disclaimer)", _
"Report Body/Content", _
"Divider", _
"Quals (Basic - Right)", _
"Quals (Basic - Left)", _
"Contact and Closing"
'Return true if any of the above names are a match
checkAllowed = True
Case Else
'Return false if no match found
checkAllowed = False
End Select
结束功能