【问题标题】:PowerPoint VBA search and delete paragraphs in NotesPowerPoint VBA 在笔记中搜索和删除段落
【发布时间】:2015-11-19 04:24:28
【问题描述】:

我有几个 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

感谢您的帮助!!

【问题讨论】:

    标签: vba powerpoint


    【解决方案1】:

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

    这是仅删除以“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
    

    【讨论】:

    • 太棒了!如果它对您有用,请随时添加投票:-)
    • 您好 user3264432。当我花时间为你写一个你说有效的解决方案时,请你投票支持我的答案吗?谢谢。
    • 我很高兴 - 但不确定如何。我点击了“绿色检查”。让我知道我还能做些什么来给你荣誉。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-22
    • 2012-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多