Results 1 to 3 of 3

Thread: Macro to find a string and copy sentence containing string

  1. #1

    Macro to find a string and copy sentence containing string


    I need help creating a Powerpoint macro.
    I would like to search in a Powerpoint document for a string. If this string is found I want to copy the sentence containing the string in a new slide in the same powerpoint document.

    I am using Microsoft PowerPoint for Office 365 MSO.

  2. #2
    VBAX Master
    Feb 2007
    This would be the basis but you might need to adapt it yourself.

    Sub chex()
    Dim osld As Slide
    Dim newsld As Slide
    Dim oshp As Shape
    Dim otr As TextRange
    Dim b_found As Boolean
    Dim s As Long
    Const Findstring As String = "This is me" ' change to suit
    For Each osld In ActivePresentation.Slides
    For Each oshp In osld.Shapes
    If oshp.HasTextFrame Then
    If oshp.TextFrame.HasText Then
    Set otr = oshp.TextFrame.TextRange
    For s = 1 To otr.Sentences.Count
    If InStr(LCase(otr.Sentences(s)), LCase(Findstring)) > 0 Then
    b_found = True
    End If
    If b_found Then Exit For
     Next s
    End If
    End If
    If b_found Then Exit For
    Next oshp
    If b_found Then Exit For
    Next osld
    If b_found Then
    Set newsld = ActivePresentation.Slides.Add(1, ppLayoutText)
    newsld.Shapes(1).TextFrame.TextRange = "Sentence Found"
    newsld.Shapes(2).TextFrame.TextRange = otr.Sentences(s)
    End If
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials

  3. #3
    Thanks John for your solution!.

    I tested and worked pretty well. Your solution helped me a lot.

    Thanks for your time and support.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts