使用 VBA 为除标题之外的整个 PPT 添加句点

Add period to entire PPT besides Titles using VBA

有没有办法在整个 PowerPoint 演示文稿(每张幻灯片的标题除外)中添加句号?

我目前正在使用下面的代码,它在所有内容后加上句号:

Sub AddPeriod()

Dim sld As Slide
Dim shp As Shape

For Each sld In ActivePresentation.Slides
    For Each shp In sld.Shapes
        shp.TextFrame.TextRange.AddPeriods
    Next shp
Next sld

End Sub

我发现最简单的方法是:

Sub AddPeriod()

    Dim sld As Slide
    Dim shp As Shape
    Dim strTitle As String

    For Each sld In ActivePresentation.Slides
        If sld.Shapes.HasTitle = True Then 'check if there is a title
            strTitle = sld.Shapes.Title.TextFrame.TextRange.Text
        Else
            strTitle = ""
        End If
        For Each shp In sld.Shapes
            'add periods only if text of shape is not equal to title text.
            If strTitle <> shp.TextFrame.TextRange.Text Then
                 shp.TextFrame.TextRange.AddPeriods
            End If
        Next shp
    Next sld

End Sub

这将检查标题的文本与形状的文本。如果它们相同,则不会添加句点。也许形状上有某种指示器表明形状是否是标题,但我找不到它。您需要检查以确保幻灯片有标题,否则从标题形状的文本中获取字符串会导致错误。