VBA powerpoint - 用于格式化笔记的宏

时间:2015-12-01 12:39:07

标签: vba powerpoint powerpoint-vba

我正在尝试创建一个宏,它可以将powerpoint演示文稿的所有音符中的所有文本更改为指定的字体和fontsize(通过InputBoxes给出)。

它似乎工作但不是在所有幻灯片中,一些幻灯片只是将fontsize重置为比给定的大。有谁知道什么可能出错?

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

2 个答案:

答案 0 :(得分:0)

似乎对我有用。如果您想要将整个文本设置为相同类型的面部和大小,我也会在删除.Paragraphs之后尝试使用它。你有一个不用于调查的例子吗?

顺便说一下,您是否知道在PowerPoint中默认不显示Notes格式并且必须在“大纲”视图中打开它?

答案 1 :(得分:0)

最初的问题是为什么代码不适用于所有幻灯片。我认为这与事实有关,即代码将Placeholder(2)用作硬值,因此该代码仅与该Placeholder中的TextRange一起使用。如果NotesPage具有多个占位符,则该代码将不适用于其他占位符。

此处显示的代码使用.HasTextFrame确定占位符是否包含文本,并且仅在设置为true时才尝试设置字体大小和类型。 (我使用debug.print查看代码的内容,您可以将其注释掉。)

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"

结束子

相关问题