How do I get the last paragraph in a TextRange?

D

David Thielen

J

\Ji Zhou [MSFT]\

Hello Dave,

Setting both of the start and length to -1 will get all of the paragraphs
returned from the Paragraphs() method. So we can get the count from its
count property. The codes will look like,

textRange =
Globals.ThisAddIn.Application.ActivePresentation.Slides[1].Shapes[1].TextFra
me.TextRange;
int count = textRange.Paragraphs(-1,-1).Count;
TextRange lastParagraph = textRange.Paragraphs(count,1);

I test the above codes and it works on my side. Please let me know if you
need any future help on this. Have a nice day!

Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Cindy M.

Hi David,
There does not appear to be any call to get the number of paragraphs
in a PPT TextRange. How can I get this?

This may be a C# issue but the only TextRange.Paragraphs method is one
that you pass a (start, length) to get back a range. There is no way
to get a count.
Mmmm. There is a Count property in VBA:

ActivePresentation.Slides(2).Shapes
(1).TextFrame.TextRange.Paragraphs.Count

But checking in C#, yes, I see what you mention. It appears that the PIA
is not picking up the PowerPoint definition of the internal Office
object. This looks like the basic Range method one sees in Word, and
which I suspect underlies all other objects that deal with text.

Best I can see is to check for the number of occurrences of the ASCII
character 13 (carriage return). That number, plus 1, would give you the
number of paragraphs. Unfortunately, a check of the string returned by
TextFrame.TextRange.Text doesn't match either "/r" or "/n" and I don't
know how to check the character codes of each individual member of a
string. (But I'd sure like to know as it would be useful for general
trouble shooting).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
C

Cindy M.

Hi Ji / David
Setting both of the start and length to -1 will get all of the paragraphs
returned from the Paragraphs() method.
This works, EXCEPT if I try it in a "Click to add Title" placeholder. That
appears to use a different character when ENTER is pressed, so the "new
lines" aren't being recognized as paragraphs. In a MessageBox, this is
showing up as a "box".

If I use the VBA Immediate Window to query the TextRange.Text I get an odd
symbol which the ASC function informs me is ANSI 11. In Word, this would be
the equivalent of pressing Shift+Enter to create a new line and indeed, this
is not considered a new paragraph.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
D

David Thielen

thank you

Hello Dave,

Setting both of the start and length to -1 will get all of the paragraphs
returned from the Paragraphs() method. So we can get the count from its
count property. The codes will look like,

textRange =
Globals.ThisAddIn.Application.ActivePresentation.Slides[1].Shapes[1].TextFra
me.TextRange;
int count = textRange.Paragraphs(-1,-1).Count;
TextRange lastParagraph = textRange.Paragraphs(count,1);

I test the above codes and it works on my side. Please let me know if you
need any future help on this. Have a nice day!

Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


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