Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General PowerPoint Questions / February 2007

Tip: Looking for answers? Try searching our database.

Selecting a text box with a particular string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Janie - 14 Feb 2007 15:16 GMT
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
John Wilson - 14 Feb 2007 16:19 GMT
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?
Signature

--------------------------------------------
Amazing PPT Hints, Tips and Tutorials-http://www.PPTAlchemy.co.uk
http://www.technologytrish.co.uk/ppttipshome.html
email john AT technologytrish.co.uk

> 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?
[quoted text clipped - 4 lines]
>
> Many thankx
Janie - 14 Feb 2007 18:47 GMT
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?

> Your code has no chance at all of working I'm afraid!
> Are you trying to search one slide or the whole presentation
[quoted text clipped - 12 lines]
> >
> > Many thankx
John Wilson - 14 Feb 2007 19:49 GMT
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 
Signature

--------------------------------------------
Amazing PPT Hints, Tips and Tutorials-http://www.PPTAlchemy.co.uk
http://www.technologytrish.co.uk/ppttipshome.html
email john AT technologytrish.co.uk

> A) I really do want to select it
> B) I do not need to search an entire presentation, just a given slide
[quoted text clipped - 34 lines]
> > >
> > > Many thankx
Steve Rindsberg - 15 Feb 2007 03:21 GMT
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

> Sub findit()
> Dim oshp As Shape
[quoted text clipped - 13 lines]
> MsgBox "There's an error, maybe you didn't select anything"
> End Sub

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ:  www.pptfaq.com
PPTools:  www.pptools.com
================================================
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.