将列表元素添加到幻灯片

时间:2016-05-25 14:05:33

标签: vba powerpoint

我想将List的元素添加到一张幻灯片中。我的代码如下所示:

Sub Inhaltsverzeichnis_generator()
Set titels = New Dictionary
Set slideNr = New Collection
Dim sld As Slide
Dim inhaltsverzeichnis_Slide As Slide
Dim inhaltsverzeichnis_Shape_Titel As Shape
Dim inhaltsverzeichnis_Shape_Text As Shape  
Set inhaltsverzeichnis_Slide = Application.ActivePresentation.Slides.Add(2, ppLayoutText)

Set inhaltsverzeichnis_Shape_Titel = inhaltsverzeichnis_Slide.Shapes.AddTextbox(msoTextOrientationHorizontal, 30, 30, 650, 140)
With inhaltsverzeichnis_Shape_Titel.TextFrame.TextRange
    .Font.Name = "Arial"
    .Font.Size = 35
    .Text = "Introduction"
    .Lines.ParagraphFormat.SpaceWithin = 1.5
End With

For Each sld In ActivePresentation.Slides
    If sld.Shapes.HasTitle Then
         'Debug.Print sld.SlideIndex & ": " & sld.Shapes.Title.TextFrame.TextRange
        titels.Add (sld.Shapes.title.TextFrame.TextRange.Text)
        slideNr.Add (sld.SlideIndex)
    End If
Next
Set inhaltsverzeichnis_Shape_Text = inhaltsverzeichnis_Slide.Shapes.AddTextbox(msoTextOrientationHorizontal, 30, 110, 650, 140)
For Each title In titels
    With inhaltsverzeichnis_Shape_Text.TextFrame.TextRange
        .Font.Name = "Arial"
        .Font.Size = 10
        .Text = vbNewLine & title
    End With
Next
End Sub

我的问题是只会显示List的最后一个元素。似乎其他元素被覆盖了。

1 个答案:

答案 0 :(得分:0)

我认为这是问题所在:

.Text = vbNewLine & title

每次循环时,都会将.Text设置为title的当前值,而不是将当前title的值附加到现有文本。

将其更改为

.Text = .Text & vbNewLine & title