Using VBA to set default bullet styles in a text box in PowerPoint RRS feed

  • Question

  • Hi!

    I've Googled around quite a bit trying to find an answer to this problem, but so far to no avail (rather, I just find references to others having similar issues). Therefore, I'm hoping someone here might have an insight or two.

    I've created a ppt template in which I've changed the master slides' placeholder formats to how I want them to work in terms of bullet styles, indentation etc. This all works fine. However, I'd like to also be able to create text boxes with the same formatting as said placeholders. This appears to be a challenge. Using the code below, I've now managed to create a text box that looks correct when created, but the formatting for each indentation level appears to be forgotten as soon as I promote/demote any parapgraph. In other words, I have managed to identify the correct VBA code to generate the formatting I desire, but not what is needed for that formatting to stick in the box in question. Any ideas on this?

    Sub NewTextBox() 
        Set b = ActiveWindow.View.Slide.Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 100, 500, 100) 
        With b.TextFrame 
            .MarginTop = 0 
            .MarginBottom = 0 
            .MarginLeft = 0 
            .MarginRight = 0 
            With .TextRange 
                .Text = "Level 1" & vbCrLf & "Level 2" & vbCrLf & "Level 3" & vbCrLf & "Level 4" & vbCrLf & "Level 5" 
                With .Font 
                    .Name = "PT Sans" 
                    .Size = "16" 
                End With 
                For i = 2 To 5 
                    With .Paragraphs(i).ParagraphFormat.Bullet 
                        .Visible = True 
                        .Type = ppBulletUnnumbered 
                        .Font.Color.SchemeColor = ppTitle 
                        .RelativeSize = 1.2 
                    End With 
                With .Paragraphs(2) 
                    .IndentLevel = 2 
                    .ParagraphFormat.Bullet.Font.Name = "Wingdings" 
                    .ParagraphFormat.Bullet.Character = 167 
                End With 
                With .Paragraphs(3) 
                    .IndentLevel = 3 
                    .ParagraphFormat.Bullet.Character = 8211 
                End With 
                With .Paragraphs(4) 
                    .IndentLevel = 4 
                    .ParagraphFormat.Bullet.Font.Name = "Wingdings" 
                    .ParagraphFormat.Bullet.Character = 159 
                End With 
                With .Paragraphs(5) 
                    .IndentLevel = 5 
                    .ParagraphFormat.Bullet.Character = 111 
                    .ParagraphFormat.Bullet.RelativeSize = 1 
                End With 
            End With 
            With .Ruler 
                For i = 2 To 5 
                    .Levels(i).FirstMargin = 14 * (i - 2) 
                    .Levels(i).LeftMargin = 14 * (i - 1) 
            End With 
        End With 
    End Sub 

    Wednesday, October 26, 2011 10:11 AM


  • Hi jazdc

    You mention you've googled around - did you hit on the PowerPoint section of the Answers forums, by any chance?

    That's where most of the PowerPoint specialists (including programmers) congregate and I'll be they'd now how/if you can achieve this. There've been some major changes in the application and the object model the last couple of versions, so it will be very important that you provide the version information you're using.

    Cindy Meister, VSTO/Word MVP
    Thursday, October 27, 2011 12:44 PM