abby
abby

Reputation: 1

Powerpoint Notes Section formatting VBA

Using the following code to format the notes section of every slide to a pictured bulleted list works nearly every time, but in select presentations will give the error:

Placeholders (unknown member) : Integer is out of range. 2 is not in the valid range of 1 to 1.

This does not seem to be linked to any number of slides, whether or not the notes sections already contain text in them, etc.

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

Upvotes: 0

Views: 447

Answers (1)

John Korchok
John Korchok

Reputation: 4923

I'm curious why you're not just using the program interface to set the bullets in the Notes Master. That's a lot easier than writing VBA.

If a notes page has only 1 placeholder instead of 2, that error would occur. Here's a more robust routine that checks the shape type and whether it actually contains text or not:

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

Upvotes: 1

Related Questions