Share via

PowerPoint "TextRange" Paragraphs() / Lines() methods

Anonymous
2011-06-24T08:43:17+00:00

Hello!

I implement add-in to PowerPoint 2010 and we use Visual Studio 2010 and VSTO 4.0.

Currently I work with multi-level bulleted and numbered lists and have difficulties with  programming text paragraphs. I need to apply specific font settings (font size, style, color), bullet symbol to each indent level of bulleted list.

Please could you explain me the difference between "TextRange.Paragraps()" method and "TextRange.Lines()" method, which method should I use to apply specific settings to each list item? I need to "run" throw all items in all indent levels in bullet list.

And I will be gratehul if you suggest me how I can determine current (selected) paragraph or line - it's integer index in collection.

Thank you.

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2011-06-24T12:17:37+00:00

You should use Paragraphs I guess. Paragraphs can have more than one line if the text wraps. Your third paragraph has two lines for example.

When you say current selected paragraph do you mean the cursor could be in it (ie no text selected) The way to locate the paragraph index is to compare the paragraph end with the character start position. A little clumsy but it's the only way I know.

Sample Code (based onan idea from Shyam Pillai) Note the code assumes a textrange selection you will need to add some error checking.

Sub checkCursor()

Dim lngCharStart As Long

Dim lngParaEnd As Long

Dim L As Long

Dim oShp As Shape

lngCharStart = ActiveWindow.Selection.TextRange.Start

Set oShp = ActiveWindow.Selection.TextRange.Parent.Parent

With oShp.TextFrame2.TextRange

Debug.Print lngCharStart & .Length

If lngCharStart > .Length Then ' selection is at end!

MsgBox "Cursor is in Paragraph " & .Paragraphs.Count

Else

For L = 1 To .Paragraphs.Count

lngParaEnd = .Paragraphs(L).Start + .Paragraphs(L).Length

If lngCharStart < lngParaEnd Then

MsgBox "Cursor is in Paragraph " & L

Exit For

End If

Next L

End If

End With

End Sub

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2011-06-24T15:40:36+00:00

    Great thanks, John!! 

    This approach helps me to determine index of selected paragraph and apply styles to it

    Thank you!

    Was this answer helpful?

    0 comments No comments