Another VBA Question: Find text, delete the slide with that text?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two command buttons; I want one to look for the slide that has the
word "Jones" and delete that slide.

This is just one of the variations I've tried:

Public Function GetJones()
FindWhat = "Jones"
Dim Sld As Slide
Sld.Cut
End Function

I would be grateful for another hint as to what I'm missing here, Oh
PowerPoint Masters.

(And maybe someone could suggest a book for those of us that find us
wandering into the middle of these things without getting the basics down
first? Yes, that would be me, guilty as charged...)
 
Unfortunately, there aren't a lot of good books for using VBA in
PowerPoint. In fact, there is really only one book, and it just gets your
started with the basics. I'll let others tell you if it is any good or
not because I wrote it. You can find it at
http://www.PowerfulPowerPoint.com/

As for your question, you want to cycle through the slides and look for
the text "Jones." There are a lot of ways to do this. If you're only
looking for one instance of Jones, then this will work. If you want to
delete more than one slide at the same time, you'll have to cycle
backwards through the slides, instead of forward (as I did with the For
Each). Also if you want to match whole words and capitalization, look at
the optional parameters for the Find method that I used (as my procedure
will kill the first slide it finds with jonestown):

Sub KillJones()
Dim oSld As Slide
Dim oShp As Shape
For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
If oShp.HasTextFrame Then
If oShp.TextFrame.TextRange.Find("Jones") Is Nothing Then
'didn't find it
Else
'found it
oSld.Delete
Exit Sub
End If
End If
Next oShp
Next oSld
End Sub


--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
Sub KillJones()
Dim oSld As Slide
Dim oShp As Shape
For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
If oShp.HasTextFrame Then
If oShp.TextFrame.TextRange.Find("Jones") Is Nothing Then
'didn't find it
Else
'found it
oSld.Delete
Exit Sub
End If
End If
Next oShp
Next oSld
End Sub


--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/

=?Utf-8?B?YXZmYzRtZQ==?= <[email protected]> wrote in

I have a presentation with a certain no. of slides. I have an array (string in vba) which has the names of the slides which are not required. Each slide is assigned a name in a textbox in the presentation. I want to delete those slides whose names are there in the array. The array is dynamic. So it might have 3 names today and 4 names tomorrow. How do I delete the slides based on the array?? Pls Help
 
Back
Top