Consulting

Results 1 to 6 of 6

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

  1. #1

    Macro to find a string and copy sentence containing string

    Hi,

    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
    Joined
    Feb 2007
    Posts
    1,894
    Location
    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
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  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.

  4. #4
    VBAX Newbie
    Joined
    Feb 2020
    Location
    Chicago
    Posts
    2
    Location
    Hello, I faced the same problem, could not understand what the problem was. Your decision really helped, thanks, have a nice day!




    [COLOR=rgba(0, 0, 0, 0.54)]
    [/COLOR][COLOR=rgba(0, 0, 0, 0.54)]
    [/COLOR]










  5. #5
    How to disable the VBA command "SAVE AS" in PowerPoint 2020, can someone help me? Please

  6. #6
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,894
    Location
    That has nothing to do with the question and there is no PPT 2020.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

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