Results 1 to 11 of 11

Thread: [PPT]HELPSearch for a word in group of slides and if not found erase from title slide

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2014
    Posts
    10

    Exclamation [PPT]HELPSearch for a word in group of slides and if not found erase from title slide

    Hi there friend,

    I need some help creating a code for PowerPoint.

    What I need to do is search for particular words inside text boxes in slides >=2. Then, if any of these words are found in these slides, do nothing. But if they are not found, I need to erase, just the words, from inside a text box that I have in the title slide (slide#1).

    Can you guys help me with this? Thanks.

  2. #2
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: [PPT]HELPSearch for a word in group of slides and if not found erase from title s

    How many words will you need to search for?

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2014
    Posts
    10

    Re: [PPT]HELPSearch for a word in group of slides and if not found erase from title s

    I need to search for 6 different words.
    so essentially, I need to search for these 6 different words in slides >=2, if any of the words are found, then do nothing. if any of the words are not found then, search for the word/words that was/were not found in the title slide and erase them accordingly from the text box.
    Last edited by Rameses2; Aug 14th, 2014 at 09:51 AM.

  4. #4
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: [PPT]HELPSearch for a word in group of slides and if not found erase from title s

    Not fully tested, but try something like this:

    Code:
        Sub lookForWords()
        Dim words(5) As String
        Dim pres As Presentation
        Dim sld As Slide
        Dim j As Integer
        Dim k As Integer
        Dim m As Integer
        Dim n As Integer
        Dim splits() As String
        Dim foundWord As Boolean
        Dim strTemp As String
        
        Set pres = ActivePresentation
        
        words(0) = "word1"
        words(1) = "word2"
        words(2) = "word3"
        words(3) = "word4"
        words(4) = "word5"
        words(5) = "word6"
        
        For j = 2 To pres.Slides.Count
            Set sld = pres.Slides(j)
            If sld.Shapes.Count > 0 Then
                For k = 1 To sld.Shapes.Count
                    If sld.Shapes(k).Type = msoTextBox Then
                        splits = Split(sld.Shapes(k).TextFrame2.TextRange.Text, " ")
                        For m = 0 To UBound(splits)
                            For n = 0 To UBound(words)
                                If splits(m) = words(n) Then
                                    foundWord = True
                                    Exit For
                                End If
                            Next n
                            If foundWord = True Then Exit For
                        Next m
                    End If
                    If foundWord = True Then Exit For
                Next k
            End If
            If foundWord = True Then Exit For
        Next j
        If foundWord = False Then
            Set sld = pres.Slides(1)
            For j = 1 To sld.Shapes.Count
                If sld.Shapes(j).Type = msoTextBox Then
                    strTemp = sld.Shapes(j).TextFrame2.TextRange.Text
                    splits = Split(strTemp, " ")
                    For k = 0 To UBound(words)
                        If InStr(1, strTemp, words(k)) Then
                            strTemp = Replace(strTemp, words(k), "")
                        End If
                    Next k
                End If
            Next j
        End If
        Set sld = Nothing
        Set pres = Nothing
        
    End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2014
    Posts
    10

    Re: [PPT]HELPSearch for a word in group of slides and if not found erase from title s

    thanks I'll give it a shot, and let you know.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2014
    Posts
    10

    Re: [PPT]HELPSearch for a word in group of slides and if not found erase from title s

    I gave a try, but it did not work.

  7. #7
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: [PPT]HELPSearch for a word in group of slides and if not found erase from title s

    you will need to be more specific

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2014
    Posts
    10

    Re: [PPT]HELPSearch for a word in group of slides and if not found erase from title s

    I created a ppt to test the code, with a textbox in the title slide with the following text: "word1, word2, word3, word4". Then in slide 2 and 3 i inserted a text box with the texts "word1" and "word2" respectively. Next, I copied your code in the developer section as a module and saved the ppt as a macro-enabled powerpoint. Finally, I went to and hit run to run the code and it doesnt seem to do anything.

    May I be missing something? I was expecting for the words "word3" and "word4" to be deleted in the title slide, since they do not appear in other subsequent slides in the active ppt.

  9. #9
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: [PPT]HELPSearch for a word in group of slides and if not found erase from title s

    I will try to duplicate that scenario exactly as you describe. Have you tried stepping through and seeing if you encounter errors?

  10. #10
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: [PPT]HELPSearch for a word in group of slides and if not found erase from title s

    Too many "Exit Fors" in there. Back in a minute with the fix.

  11. #11
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: [PPT]HELPSearch for a word in group of slides and if not found erase from title s

    Ok, I think this will be closer, see what you think:

    Code:
    Sub lookForWords()
        Dim words(3) As String
        Dim words2(3) As String
        Dim pres As Presentation
        Dim sld As Slide
        Dim j As Integer
        Dim k As Integer
        Dim m As Integer
        Dim n As Integer
        Dim splits() As String
        Dim foundWord As Boolean
        Dim strTemp As String
        
        Set pres = ActivePresentation
        
        words(0) = "word1"
        words(1) = "word2"
        words(2) = "word3"
        words(3) = "word4"
        
        For j = 0 To 3
            words2(j) = words(j)
        Next j
        
        For j = 2 To pres.Slides.Count
            Set sld = pres.Slides(j)
            If sld.Shapes.Count > 0 Then
                For k = 1 To sld.Shapes.Count
                    If sld.Shapes(k).Type = msoTextBox Then
                        splits = Split(sld.Shapes(k).TextFrame2.TextRange.Text, " ")
                        For m = 0 To UBound(splits)
                            For n = 0 To UBound(words)
                                If splits(m) = words(n) Then
                                    foundWord = True
                                    words2(n) = "FOUND"
                                    Exit For
                                End If
                            Next n
                            If foundWord = True Then Exit For
                        Next m
                    End If
                Next k
            End If
        Next j
            Set sld = pres.Slides(1)
            For j = 1 To sld.Shapes.Count
                If sld.Shapes(j).Type = msoTextBox Then
                    strTemp = sld.Shapes(j).TextFrame2.TextRange.Text
                    splits = Split(strTemp, " ")
                    For k = 0 To UBound(words2)
                        If words2(k) = "FOUND" Then
                            'do nothing
                        ElseIf InStr(1, strTemp, words2(k)) Then
                            strTemp = Replace(strTemp, words2(k), "")
                        End If
                    Next k
                    sld.Shapes(j).TextFrame2.TextRange.Text = strTemp
                End If
            Next j
        Set sld = Nothing
        Set pres = Nothing
        
    End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width