首页 > 解决方案 > Powerpoint Notes 部分格式化 VBA

问题描述

使用以下代码将每张幻灯片的注释部分格式化为带图的项目符号列表几乎每次都有效,但在选择的演示文稿中会出现错误:

占位符(未知成员):整数超出范围。2 不在 1 到 1 的有效范围内。

这似乎与任何数量的幻灯片无关,无论注释部分是否已包含文本等。

Sub Button1()
  Dim intSlide As Integer

With ActivePresentation

For intSlide = 1 To .Slides.Count

With ActivePresentation.Slides(intSlide).NotesPage. _
            Shapes.Placeholders(2).TextFrame.TextRange
    With .ParagraphFormat.Bullet
        .Type = ppBulletPicture
        .Picture ("/Applications/Microsoft Office/picture.JPG")
        .RelativeSize = 1.4
    End With
     End With
Next intSlide
End With
End Sub

标签: powerpoint

解决方案


我很好奇您为什么不只是使用程序界面来设置 Notes Master 中的项目符号。这比编写 VBA 容易得多。

如果注释页面只有 1 个占位符而不是 2 个,则会发生该错误。这是一个更强大的例程,用于检查形状类型以及它是否实际包含文本:

Sub Button1()
    Dim oSlide As Slide
    Dim oShape As Shape
    
    For Each oSlide In ActivePresentation.Slides
        For Each oShape In oSlide.NotesPage.Shapes
            If oShape.Type = msoPlaceholder Then
                If oShape.PlaceholderFormat.Type = ppPlaceholderBody Then
                    If oShape.HasTextFrame Then
                        If oShape.TextFrame.HasText Then
                            With oShape.TextFrame.TextRange.ParagraphFormat.Bullet
                                .Type = ppBulletPicture
                                .Picture ("C:/picture.png")
                                .RelativeSize = 1.4
                            End With
                        End If
                    End If
                End If
            End If
        Next oShape
    Next oSlide
End Sub

推荐阅读