Selecting a text box with a particular string

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

Guest

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
 
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?
 
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?
 
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
 
Hey John,

I'll see your FindIt and raise you one. This is missing the cautionary code
but it does find and select the requested text within a text box. I think
yours will only work if the entire contents of the text box matches the search
string.

Sub FinditBetter(sSearchString As String)

Dim oSh As Shape
Dim oRng As TextRange

For Each oSh In ActiveWindow.Selection.SlideRange.Shapes

If oSh.HasTextFrame Then
If oSh.TextFrame.HasText Then
' is the search string found in this text box?
If InStr(oSh.TextFrame.TextRange.Text, _
sSearchString) > 0 Then
' where in the text box?
' WATCH OUT FOR LINE BREAKS; THIS IS ALL ON ONE LINE:
Set oRng =
oSh.TextFrame.TextRange.Characters(InStr(oSh.TextFrame.TextRange.Text,
sSearchString), Len(sSearchString))

oRng.Select
End If
End If
End If
Next

End Sub

And to use it, you can type:

finditbetter "Def"

into the immediate box or get fancy and add an input box to the macro to get
the text to search for.

Not perfect ... it can be thrown off by linebreaks in textboxes, but still ...
not bad
 
Back
Top