'VBA powerpoint - Macro for formatting notes

I'm trying to make a macro that can change all the text in all the notes of a powerpoint presentation to a specified font and fontsize (given through InputBoxes).

It seems to work but not in all the slides, some slides it just resets the fontsize to something way larger than what was given. anyone know what could go wrong?

Sub FormatNotes()

    Dim intSlide As Integer
    Dim strNotes As String
    Dim nts As TextRange
    Dim strFont, intSize

    intSize = InputBox("Please enter font size", "fontsize", "12")
    strFont = InputBox("Please enter font", "font type", "Calibri")

        With ActivePresentation

            For intSlide = 1 To .Slides.Count
            Set nts = ActivePresentation.Slides(intSlide).NotesPage. _
            Shapes.Placeholders(2).TextFrame.TextRange
            With nts
                If intSize = "" Then intSize = 12
                .Paragraphs.Font.Size = intSize
                .Paragraphs.Font.Name = strFont

        End With 

            Next intSlide
    End With
   MsgBox ("FormatNotes uitgevoerd")

End Sub


Solution 1:[1]

Seems to work to me. I also tried it after deleting .Paragraphs as you don't need that if you want to set the whole text to the same type face and size. Do you have an example of it not working for investigation?

By the way, did you know that Notes formatting is not shown by default in PowerPoint and has to be turned on in the Outline view?

Solution 2:[2]

Original question is why code did not work for all slides. I think it has to do with fact the code used Placeholder(2) as hard value, so the code only works with TextRange in that Placeholder. If the NotesPage has more than one Placeholder, the code will not work for the other Placeholders.

My code shown here uses .HasTextFrame to determine if a Placeholder has text, and only attempts to set font size and type if this is true. (I used debug.print to see how far the code got, you can comment it out.)

Sub FormatNotes()
    ' Written 2020-08-29     P.Irving   for myself
    Dim mySlide As Integer, myPlace As Integer
    Dim myNotes As String
    Const mySize = "11", myFont = "Calibri"
    With ActivePresentation     ' qualify macro name
    Debug.Print "Slide#", "LEN(Notes)", "LEFT(Notes,50)"
    For mySlide = 1 To .Slides.Count
        myNotes = ""
        For myPlace = 1 To ActivePresentation.Slides(mySlide). _
                           NotesPage.Shapes.Placeholders.Count
            ' code copied from docs.microsoft.com/en-us/office/_
            '                vba/api/powerpoint.textrange.font
            ' this code does not attempt to SET nts
            With ActivePresentation.Slides(mySlide). _
                 NotesPage.Shapes.Placeholders(myPlace)
                If .HasTextFrame Then
                    With .TextFrame.TextRange.Font
                        .Size = mySize
                        .Name = myFont
                        '.Bold = True
                        '.Color.RGB = RGB(255, 127, 255)
                    End With
                    myNotes = myNotes & _
                              ActivePresentation.Slides(mySlide). _
                              NotesPage.Shapes.Placeholders(myPlace). _
                              TextFrame.TextRange
                End If  ' .HasText
            End With
        Next myPlace
        Debug.Print mySlide, Len(myNotes), Left(myNotes, 50)
    Next mySlide
    End With
    MsgBox "Applied to " & ActivePresentation.Slides.Count & " slides", _
            vbOKOnly, "FormatNotes"
End Sub

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jamie Garroch - MVP
Solution 2 jessehouwing