The following command deletes at once an array of slides from a presentation:
以下命令一次删除演示文稿中的幻灯片数组:
ActivePresentation.Slides.Range(Array(1, 5, 69, 70.....)).delete
But how do I add a specific slide to the array (if the slide meet some condition) before proceeding to deletion?
但是,在继续删除之前,如何向阵列添加特定幻灯片(如果幻灯片满足某些条件)?
1 个解决方案
#1
2
According to MSDN, the parameter sent to the Range function can be an Integer index, a String slide name, or an Array of Integers and Strings. If you wish to use a SlideRange to perform your delete, you can define the array first, add whatever slides you wish by name or index number and then load the SlideRange and perform the delete:
根据MSDN,发送到Range函数的参数可以是Integer索引,String幻灯片名称或整数和字符串数组。如果您希望使用SlideRange执行删除,可以先定义数组,按名称或索引编号添加所需的幻灯片,然后加载SlideRange并执行删除:
Public Sub Test()
Dim arrSlides() As Variant
arrSlides = Array(1, 2, 69, 70)
'Put this next part in a loop to continue adding more slides
ReDim Preserve arrSlides(UBound(arrSlides) + 1)
arrSlides(4) = 83 ' or "Name Of Slide"
Application.ActivePresentation.Slides.Range(arrSlides).Delete
End Sub
Alternative Solution
If your goal is to delete slides that match a specific criteria, it's probably easier just to iterate through them all and delete them. This way you have greater freedom to test the specific properties of each individual slide.
如果您的目标是删除符合特定条件的幻灯片,则可能更容易迭代它们并删除它们。这样,您就可以更*地测试每张幻灯片的特定属性。
Public Sub Test()
Dim tempSlide As Slide
For Each tempSlide In Application.ActivePresentation.Slides
If tempSlide.Shapes.Count > 3 Then 'Or whatever your condition actually is
tempSlide.Delete
End If
Next
End Sub
#1
2
According to MSDN, the parameter sent to the Range function can be an Integer index, a String slide name, or an Array of Integers and Strings. If you wish to use a SlideRange to perform your delete, you can define the array first, add whatever slides you wish by name or index number and then load the SlideRange and perform the delete:
根据MSDN,发送到Range函数的参数可以是Integer索引,String幻灯片名称或整数和字符串数组。如果您希望使用SlideRange执行删除,可以先定义数组,按名称或索引编号添加所需的幻灯片,然后加载SlideRange并执行删除:
Public Sub Test()
Dim arrSlides() As Variant
arrSlides = Array(1, 2, 69, 70)
'Put this next part in a loop to continue adding more slides
ReDim Preserve arrSlides(UBound(arrSlides) + 1)
arrSlides(4) = 83 ' or "Name Of Slide"
Application.ActivePresentation.Slides.Range(arrSlides).Delete
End Sub
Alternative Solution
If your goal is to delete slides that match a specific criteria, it's probably easier just to iterate through them all and delete them. This way you have greater freedom to test the specific properties of each individual slide.
如果您的目标是删除符合特定条件的幻灯片,则可能更容易迭代它们并删除它们。这样,您就可以更*地测试每张幻灯片的特定属性。
Public Sub Test()
Dim tempSlide As Slide
For Each tempSlide In Application.ActivePresentation.Slides
If tempSlide.Shapes.Count > 3 Then 'Or whatever your condition actually is
tempSlide.Delete
End If
Next
End Sub