PDA

View Full Version : Bullet indent at different levels



magnel
10-04-2016, 09:29 AM
Hello John,

I am using PPT 2010. I was trying to figure out the right code which will allow me to add a bullet to the selected paragraph and indent to second level or third level (not indenting together for all level but separately for each level).

I was refering to the solution on the below thread, but didn't work out.
http://www.vbaexpress.com/forum/showthread.php?52890-Macros-defining-levels-for-selected-text-paragraphs&highlight=bullet

Please can you help me with a piece of code for indenting the paragraph with a bullet added for just the second level, I will do the same for the next few levels.

Thank you so much

John Wilson
10-06-2016, 01:30 PM
See if this gets you on track.

To indent by paragraph you need to use the new (in 2010) TextFrame2 and TextRange2 objects.


Sub secondlevel()
Dim otr2 As TextRange2
' assumes the placeholder is selected
Set otr2 = ActiveWindow.Selection.ShapeRange(1).TextFrame2.TextRange.Paragraphs(2)
With otr2.ParagraphFormat
.IndentLevel = 2
End With
End Sub

magnel
10-09-2016, 12:08 AM
Hi John,

Thanks for this piece. This one move only the second para to the 2nd level, not the selected para(s).
Have been struggling for the same from many days, cannot find the right one which will work best on the selected para whether the para is in a textbox or a table.

John Wilson
10-10-2016, 10:25 AM
I misunderstood

You would need to build a function to find the selected paragraph


Sub selectedLevel()
Dim otr2 As TextRange2
' assumes the placeholder is selected
Set otr2 = ActiveWindow.Selection.ShapeRange(1).TextFrame2.TextRange.Paragraphs(GetPar a)
With otr2.ParagraphFormat
.IndentLevel = 2
End With
End Sub




Function GetPara() As Long
Dim lngStart As Long
Dim oshp As Shape
Dim L As Long
On Error Resume Next
lngStart = ActiveWindow.Selection.TextRange.Start
If Err.Number <> 0 Then
Exit Function
End If
On Error GoTo 0
Set oshp = ActiveWindow.Selection.ShapeRange(1)
If (oshp.HasTextFrame) Then
For L = 1 To oshp.TextFrame2.TextRange.Paragraphs.Count
If (oshp.TextFrame2.TextRange.Paragraphs(L).Start <= lngStart) And ((oshp.TextFrame2.TextRange.Paragraphs(L).Start + oshp.TextFrame2.TextRange.Paragraphs(L).Length - 1) >= lngStart) Then
GetPara = L
Exit Function
End If
Next L
End If
End Function

This would need to be adapted if you have a table and tables don't really have levels in the same way as placeholders. Check which cell is selected and then check the text in

otbl.Cell(row,column).Shape where Cell(row,column) is the selected cell

magnel
10-15-2016, 12:12 PM
Hello John,

Thanks for the code, while trying to use it, if I have selected more than one para, only the first para gets indented to the second level.
Have been trying to alter the code, but this one seems to be a complex one for me.

Please can you check.

John Wilson
10-16-2016, 03:31 AM
The previous code allowed for the user just putting the curer in the paragraph. As long as the whole text is being selected try:


Sub allParas()
Dim L As Long
Dim otr2 As TextRange2
On Error Resume Next
For L = 1 To ActiveWindow.Selection.TextRange2.Paragraphs.Count
Set otr2 = ActiveWindow.Selection.TextRange2.Paragraphs(L)
otr2.ParagraphFormat.IndentLevel = 3
Next L
End Sub

magnel
10-19-2016, 02:14 AM
Wow, thank you so much John. Its working and moving the selected paras to the third level.