juanbolas
juanbolas

Reputation: 21

How to format bullets and indents using PowerPoint VBA?

I'm trying to automatically format a series of tables with three bullet indent styles.

1 - no indent, no bullet
2 - no indent, bullet
3 - indent, dash

When I set it up manually its:

Manual inputs in paragraph dialog box (in cms)
1 - 0 Before text, 0 hanging
2 - 0,5 before text, 0,5 hanging
3 - 1,0 before text, 0,5 hanging

I adapted the following code but it does not give me the desired results.

Sub TableBullets2()
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
                    .ParagraphFormat.FirstLineIndent = 0
                    .ParagraphFormat.LeftIndent = 0
                    With .ParagraphFormat.Bullet
                        .Visible = False
                        With .Font
                            .Name = "Arial"
                            .Fill.ForeColor.RGB = RGB(0, 0, 0)
                        End With
                        .Character = 8226
                    End With
                Case Is = 2
                    .ParagraphFormat.Alignment = ppAlignLeft
                    .ParagraphFormat.FirstLineIndent = cm2Points(-0.5)
                    .ParagraphFormat.LeftIndent = cm2Points(0.5)
                    With .ParagraphFormat.Bullet
                        .Visible = msoTrue
                        With .Font
                            .Name = "Arial"
                            .Fill.ForeColor.RGB = RGB(0, 0, 0)
                        End With
                        .Character = 8226
                    End With
                Case Is = 3
                    .ParagraphFormat.Alignment = ppAlignLeft
                    .ParagraphFormat.FirstLineIndent = cm2Points(-0.5)
                    .ParagraphFormat.LeftIndent = cm2Points(1.0)
                    With .ParagraphFormat.Bullet
                        .Visible = msoTrue
                        With .Font
                            .Name = "Arial"
                            .Fill.ForeColor.RGB = RGB(0, 0, 0)
                        End With
                        .Character = 8211
                        .RelativeSize = 0.9
                    End With
                End Select
            End With
        Next I
    End If
End With
End Sub

Upvotes: 0

Views: 520

Answers (1)

John Korchok
John Korchok

Reputation: 4913

VBA is not the best solution for this problem. Instead, hack the otherStyle section of slideMaster1.xml, creating your text levels there. Here's my article on how to do this: OOXML Hacking: Default Table Text

All PowerPoint text style sections have identical syntax, so if you use the interface to set up your bullet styles on the slide master or a slide layout, then you can just copy and paste the XML into the otherStyle section. No programming required, and every new table will automatically have the same styling without running a macro.

Upvotes: 1

Related Questions