VBA / Powerpoint:如何列出哪些幻灯片属于任何现有幻灯片母版?

时间:2017-11-09 20:31:46

标签: vba powerpoint powerpoint-vba

我是VBA的完全初学者,并从现有的宏和大量Google搜索中学习。

我想生成一个消息框,列出幻灯片母版名称以及在演示文稿中为每个母版使用该母版本的幻灯片。像这样:

SlideMaster1:1, 2, 5, 7

SlideMaster2:3, 4, 6, 8

SlideMaster3:No slides

我一直在使用一些代码来枚举http://skp.mvps.org/designs.htm中的Designs / Masters,现在它非常粗糙和基本。

Sub ListSlidesinMasters()

Dim lCtrA As Integer
Dim oPres As Presentation

Set oPres = ActivePresentation
With oPres
        For lCtrA = 1 To .Designs.Count
         MsgBox "Number of masters: " & .Designs.Count & vbCrLf & .Designs(lCtrA).Name & ": " & "unknown" & vbCrLf & "Slide # for active slide: " & ActiveWindow.Selection.SlideRange.SlideIndex

    Next lCtrA
End With
End Sub

1 个答案:

答案 0 :(得分:0)

这应该有所帮助:

Sub Thing()
    Dim oMaster As Design
    Dim oPres As Presentation
    Dim oSl As Slide
    Dim sTemp As String

    Set oPres = ActivePresentation

    For Each oMaster In oPres.Designs

        sTemp = sTemp & oMaster.Name & vbTab

        For Each oSl In oPres.Slides
            If oSl.Design.Name = oMaster.Name Then
                sTemp = sTemp & CStr(oSl.SlideIndex) & ", "
            End If
        Next

        sTemp = sTemp & vbCrLf

    Next

    Debug.Print sTemp

End Sub