PDA

View Full Version : [SOLVED:] Powerpoint table bullets



StarPig
12-30-2018, 05:56 AM
Hello John. From a closed thread I took the below code, but I fail to make it work for selected text in tables (I renamed the Sub). For example, it works fine in text boxes, for selected (highlighted) text. I would be nice to have this feature work in tables. Happy New Year


Sub TableBullets()
With Application.ActiveWindow.Selection
If .Type = ppSelectionText Then
I = 1
For I = 1 To .TextRange.Paragraphs.Count
With .TextRange.Paragraphs(Start:=I, Length:=1)
Select Case .IndentLevel
Case Is = 1
.ParagraphFormat.Alignment = ppAlignLeft
.Parent.Ruler.Levels(I).FirstMargin = 0
.Parent.Ruler.Levels(I).LeftMargin = 15
With .ParagraphFormat.Bullet
.visible = msoCTrue
With .Font
.Name = "Wingdings"
.Color.RGB = RGB(0, 0, 0)
End With
.Character = 167
End With
Case Is = 2
.ParagraphFormat.Alignment = ppAlignLeft
.Parent.Ruler.Levels(I).FirstMargin = 16
.Parent.Ruler.Levels(I).LeftMargin = 31
With .ParagraphFormat.Bullet
.visible = msoCTrue
With .Font
.Name = "Arial"
.Color.RGB = RGB(0, 0, 0)
End With
.Character = 8211
End With
Case Is = 3
.ParagraphFormat.Alignment = ppAlignLeft
.Parent.Ruler.Levels(I).FirstMargin = 32
.Parent.Ruler.Levels(I).LeftMargin = 47
With .ParagraphFormat.Bullet
.visible = msoCTrue
With .Font
.Name = "Wingdings"
.Color.RGB = RGB(0, 0, 0)
End With
.Character = 167
.RelativeSize = 0.9
End With
End Select
End With
Next I
End If
End With
End Sub

John Wilson
12-30-2018, 07:44 AM
This is Legacy code from v. 2003.

Starting with v.2007 the new Textrange2 object should be used together with LeftIndent and FirstLine Indent NOT Ruler and Left/First margins

People often use the old code because there are plenty of examples out there, it's easier to understand and as long as it's a simple use (eg a textbox) it still works (sort of). You should use the new TextRange2 object with modern versions.

Tables are not a simple use.

This is the updated code and will work in textboxes too.


Sub TableBullets()
Dim I As Integer
With Application.ActiveWindow.Selection
If .Type = ppSelectionText Then
I = 1
For I = 1 To .TextRange2.Paragraphs.Count
With .TextRange2.Paragraphs(I)
Select Case .ParagraphFormat.IndentLevel
Case Is = 1
.ParagraphFormat.Alignment = ppAlignLeft
'NOTE The FirstLineIndent is essentially how far Behind the
'left indent the bullet appears. Usually it stays constant
' hard to understand at first
.ParagraphFormat.FirstLineIndent = -15
.ParagraphFormat.LeftIndent = 15
With .ParagraphFormat.Bullet
.Visible = msoCTrue
With .Font
.Name = "Wingdings"
.Fill.ForeColor.RGB = RGB(0, 0, 0)
End With
.Character = 167
End With
Case Is = 2
.ParagraphFormat.Alignment = ppAlignLeft
.ParagraphFormat.FirstLineIndent = -15
.ParagraphFormat.LeftIndent = 30
With .ParagraphFormat.Bullet
.Visible = msoCTrue
With .Font
.Name = "Arial"
.Fill.ForeColor.RGB = RGB(0, 0, 0)
End With
.Character = 8211
End With
Case Is = 3
.ParagraphFormat.Alignment = ppAlignLeft
.ParagraphFormat.FirstLineIndent = -15
.ParagraphFormat.LeftIndent = 45
With .ParagraphFormat.Bullet
.Visible = msoCTrue
With .Font
.Name = "Wingdings"
.Fill.ForeColor.RGB = RGB(0, 0, 0)
End With
.Character = 167
.RelativeSize = 0.9
End With
End Select
End With
Next I
End If
End With
End Sub