Getting selected TextRange

D

David Thielen

Hi;

For a Selection sel, to get the TextRange, we have found that we need
to do:

TextRange fullText;
if (sel.Type == PpSelectionType.ppSelectionText)
{
Microsoft.Office.Interop.PowerPoint.ShapeRange spRange =
sel.ShapeRange;
Microsoft.Office.Interop.PowerPoint.Shape shapeOn =
spRange[1];
fullText = shapeOn.TextFrame.TextRange;
}

Because sel.TextRange throws an exception when getting some properties
like BoundLeft (when the selection Length == 0) and returns a
different value when there is a length.

Shouldn't both of these TextRanges be the same?

thanks - dave

david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
D

David Thielen

Got it on the bounds - I was missing something there.

But as I put in another post, I get cases where many of the properties
throw an exception. Any idea why that happens?

thanks - dave


I'm not sure why you're getting an error in some cases, but if the text
is, for example, center-aligned, the BoundLeft property will change as
you add more and more characters. The text will stay centered and
BoundLeft and .BoundWidth will increase by equal amounts.

For a Selection sel, to get the TextRange, we have found that we need
to do:

TextRange fullText;
if (sel.Type == PpSelectionType.ppSelectionText)
{
Microsoft.Office.Interop.PowerPoint.ShapeRange spRange =
sel.ShapeRange;
Microsoft.Office.Interop.PowerPoint.Shape shapeOn =
spRange[1];
fullText = shapeOn.TextFrame.TextRange;
}

Because sel.TextRange throws an exception when getting some properties
like BoundLeft (when the selection Length == 0) and returns a
different value when there is a length.

Shouldn't both of these TextRanges be the same?

thanks - dave

david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
D

David Thielen

I believe it is but I am new to PPT (lots of time on Word and Excel)
and so I may be missing something.

thanks - dave


David Thielen said:
Got it on the bounds - I was missing something there.

But as I put in another post, I get cases where many of the properties
throw an exception. Any idea why that happens?

Not really, as I mentioned below. Unless it's to do with the current
selection not being text. Are you testing for that?

ActiveWindow.Selection.Type will return one of four values, depending on
whether the current selection is Slides, Shapes, Text or nothing.

thanks - dave

I'm not sure why you're getting an error in some cases, but if the text
is, for example, center-aligned, the BoundLeft property will change as
you add more and more characters. The text will stay centered and
BoundLeft and .BoundWidth will increase by equal amounts.


For a Selection sel, to get the TextRange, we have found that we need
to do:

TextRange fullText;
if (sel.Type == PpSelectionType.ppSelectionText)
{
Microsoft.Office.Interop.PowerPoint.ShapeRange spRange =
sel.ShapeRange;
Microsoft.Office.Interop.PowerPoint.Shape shapeOn =
spRange[1];
fullText = shapeOn.TextFrame.TextRange;
}

Because sel.TextRange throws an exception when getting some properties
like BoundLeft (when the selection Length == 0) and returns a
different value when there is a length.

Shouldn't both of these TextRanges be the same?

thanks - dave

david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm

david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 

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