Selecting a text box with a particular string

J

Janie

I am trying to hunt for a text box with a particular string. But if I put
the phrase below in the immediate window I get an error. What is missing?

ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Text("XYZ").Select

As usual, the Help feature in PPT is U-S-E-L-E-S-S!

Many thankx
 
J

John Wilson

Your code has no chance at all of working I'm afraid!
Are you trying to search one slide or the whole presentation
Are you looking for a text box that contains "xyz" (and other things) or a
text box that JUST contains "xyz"

Do you really want to select the text box or would a report on where it
(they) is /are be better?
 
J

Janie

A) I really do want to select it
B) I do not need to search an entire presentation, just a given slide
C) the string is exactly "xyz"

There is a stack of text boxes because this slide has many animations and as
each event happens the appropriate text box appears. Rather than have to
manually dig through the stack to find the one that needs fixing, I wanted to
merely issue the command in the immediate window to find the one that has
that particular phrase.

ActiveWindow.Selection.SlideRange.Shapes("ABC").Select

which selects a shape whose Name Property is "ABC". Works like a champ.
So, it would seem plausible that

ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Text("XYZ").Select

would make sense to select the the shape whose Text Property is "XYZ".
Well, so much for logical thinking. Soooo ... if a person wants to only find
the one text box that has just one particular phrase in it, how would the
statement be written?
 
J

John Wilson

Janie

This code will find the first instance of "xyz" on a selected slide

Sub findit()
Dim oshp As Shape

On Error GoTo err
If ActiveWindow.Selection.SlideRange.Count <> 1 Then Exit Sub
For Each oshp In ActiveWindow.Selection.SlideRange.Shapes
If oshp.HasTextFrame Then
If oshp.TextFrame.TextRange = "xyz" Then
oshp.Select
Exit Sub ' remove this line to select last
End If
End If
Next oshp
Exit Sub
err:
MsgBox "There's an error, maybe you didn't select anything"
End Sub

Remove the line exit sub indicated and it would find the last instance

Need some vba hints - have a look at my site http://www.PPTAlchemy.co.uk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top