PPT 2007 VBA: How to retrieve selected text from grouped shapes

G

Guest

Suppose I have grouped a textbox and some sort of graphic. Now I select just
a part of the text.

ActiveWindow.Selection.Type will show as ppSelectedText, but I cannot use
ActiveWindow.Selection.TextRange to get at the selected text, because VBA
says the selection consists of multiple shapes. (??? This problem doesn't
exist if we're not talking about grouped shapes.) I have thrashed around
trying various techniques, and examined a lot of objects in debug, but I
can't seem to find any place or path that will lead me to something that
represents *only* the selected text.

I'd like (in VBA) to get a textrange that represents *just* the selected
text. Is that possible? How?

Thanks!
 
G

Guest

Hi Chiraq:

In my code, I am selecting a contiguous subset of the characters in the
textbox text string. When I've issued that select (in debug) I see the
selected letters grayed, and also the placeholders for the group and for the
textbox are shown as dashed lines. (They were not previously selected - my
code is working through all the shapes on the slide loooking for specific
text sequences.)

If I look at the ActiveWindow.Selection object immediately following that
..select, the value shown for the textrange for that object is "This member
can only be accessed for a single shape" - this is the same error message I
get if I try to reference ActiveWindow.Selection.TextRange ...

I'm curious: did you select the text manually, or in code? And if there's
any differences in behaviour that we should expect?

Here's the VBA statement that does the selection (beware of line wrap):

tRanges(i).Paragraphs(k).Sentences(l).Characters(matchedPos + 1,
Len(matchedStr)).Select

Do you see anything suspect there, Chiraq?

Thanks for your help!

--
Dave Jenkins
K5KX


Chirag said:
Hi Dave,

I am able to retrieve the selected text using
ActiveWindow.Selection.TextRange from a grouped text and graphic shape with
partial text selected from the text shape. What error does it throw at you?

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
 
C

Chirag

I was selecting text manually. That aside, since you are selecting the text
through VBA and hence you already know that text position, why bother
selecting and then getting a reference to TextRange? You can get access to
the text directly as:

tRanges(i).Paragraphs(k).Sentences(l).Characters(matchedPos + 1,
Len(matchedStr))

Does this not work for you?

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
 
G

Guest

Hi Chirag:

I'm interested in your opinion as to whether this is "to-be-expected"
behavior on the part of the Select, or is possibly a bug? (I also forgot to
say that I am *not* on the SP1 Beta.)

As far as my particular problem is concerned, I need to select the text,
because I'm indicating to the user where a change will be taking place.
However, I've got a pretty good workaround: I just unselect the current
selection when I'm through with the processing of that particular element.
 
G

Guest

I think I responded a little too quickly.

I *have* fixed one element of the problem by doing the unselect. However,
in other cases I have to allow the user to do a select and then I operate on
the selected text. To test, I manually select a portion of text in a grouped
item. When looking at the slide, I see the selected text has been
highlighted, and the placeholders for both the entire group and the
individual textbox are made visible. In debug, if I do a Watch on
ActiveWindow.Selection, it shows the Type attribute = ppSelectionText, but
the TextRange attribute is not accessible due to the message as shown in my
previous post.

It seems to me that this procedure duplicates the same test you did, where
you could access the TextRange attribute - does it? And if so, are you using
the SP1 beta? If not, I'd like to duplicate the very same steps you followed
in being able to access that selected text - I sure can't do it here!

Thanks.
 
G

Guest

I've done some more defintive testing, and here are the results:

The test case procedure is this:

1) Create two text boxes
2) Group them
3) Select some text in one of the textboxes
4) Shift to the Visual Basic Editor
5) Display the attributes of ActiveWindow.Selection

In PPT 2003:
You will see that ActiveWindow.Selection.TextRange can be accessed, and
has a
.text attribute of the text you selected in step 3.

In PPT 2007:
You will see that even though ActiveWindow.Selection.Type =
ppSelectionText,
the value for the .TextRange is "<This member can only be accessed for a
single shape>" and any attempt to reference that member will result in a
runtime error.

Can someone take ownership of this problem and take the necessary steps to
get it
inserted into the MS bug reporting and repair process?
 

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