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

PowerPoint VBA搜索和删除笔记中的段落,vba,powerpoint,Vba,Powerpoint,我有几个PowerPoints,笔记中有大量文本。我需要搜索注释文本并删除任何以“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.TextRan

我有几个PowerPoints,笔记中有大量文本。我需要搜索注释文本并删除任何以“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”开头的段落


伟大的如果它对您有效,请随意添加投票:-)Hi user3264432。由于我花时间为你们写了一个你们认为有效的解决方案,请你们投票支持我的答案好吗?谢谢。我很高兴——但不知道怎么做。我点击了“绿色支票”。让我知道我还能做些什么来给你信用。
' 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