-
Aug 14th, 2014, 06:27 AM
#1
Thread Starter
New Member
[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.
-
Aug 14th, 2014, 09:19 AM
#2
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?
-
Aug 14th, 2014, 09:46 AM
#3
Thread Starter
New Member
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.
-
Aug 14th, 2014, 10:20 AM
#4
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
-
Aug 14th, 2014, 10:29 AM
#5
Thread Starter
New Member
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.
-
Aug 14th, 2014, 10:22 PM
#6
Thread Starter
New Member
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.
-
Aug 15th, 2014, 07:13 AM
#7
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
-
Aug 15th, 2014, 07:31 AM
#8
Thread Starter
New Member
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.
-
Aug 15th, 2014, 07:43 AM
#9
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?
-
Aug 15th, 2014, 07:48 AM
#10
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.
-
Aug 15th, 2014, 08:02 AM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|