Consulting

Results 1 to 7 of 7

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
    2,093
    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
    2,093
    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

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Quote Originally Posted by MarceloTagut View Post
    How to disable the VBA command "SAVE AS" in PowerPoint 2020, can someone help me? Please
    We're glad to try and answer questions, but it's not polite to hijack another thread instead of starting your own new one, especially when your question is so different

    Top left of the first page in each forum is a button (+Post New Thread) that you can use

    Also, take a few minutes and read the FAQ link in my signature
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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