PowerPoint VBA 搜索和删除笔记中的段落

PowerPoint VBA search and delete paragraphs in Notes

我有几张 PowerPoint 演示文稿,注释中有大量文字。我需要搜索注释文本并删除任何以 "A."

开头的段落

这是我尝试过的 - 但出现类型不匹配错误

  Dim curSlide As Slide
  Dim curNotes As Shape
  Dim x As Long

  For Each curSlide In ActivePresentation.Slides
    Set curNotes = curSlide.NotesPage.Shapes(2).TextFrame.TextRange

    With curNotes.TextFrame.TextRange
        For x = 1 To Len(curNotes.TextFrame.TextRange)
            If Mid(curNotes.TextFrame.TextRange, x, 2) = "A." Then
                curNotes.TextFrame.TextRange.Paragraphs = ""
            End If
        Next x
    End With

  Next curSlide

End Sub

感谢您的帮助!!

每当您尝试分配变量指定的不同类型的数据时,都会出现不匹配错误。这发生在您的代码中,因为您将 curNotes 定义为 Shape 类型,然后尝试将该对象变量设置为不同的数据类型 TextRange。然后您尝试将对象 TextRange 作为字符串处理。您需要处理 .TextRange 的 .Text 子项 Mid 的使用不检查字符串的开头,最后,当您将文本设置为“”时,您将删除注释中的所有文本,但这不是您想要的说你在努力。

这是更正后的代码,仅删除以 "A."

开头的段落
' PowerPoint VBA macro to delete all slide note paragraphs starting with the string "A."
' Rewritten by Jamie Garroch of youpresent.co.uk
Option Explicit

Sub DeleteNoteParagraphsStartingA()
  Dim curSlide As Slide
  Dim curNotes As TextRange
  Dim iPara As Long

  For Each curSlide In ActivePresentation.Slides
    Set curNotes = curSlide.NotesPage.Shapes(2).TextFrame.TextRange

    With curNotes
      ' Count backwards in any collection when deleting items from it
      For iPara = .Paragraphs.Count To 1 Step -1
        If Left(.Paragraphs(iPara), 2) = "A." Then
          .Paragraphs(iPara).Delete
          Debug.Print "Paragraph " & iPara & " deleted from notes pane on slide " & curSlide.SlideIndex
        End If
      Next
    End With

  Next curSlide
End Sub