Creating nested bullet list in PowerPoint 2007
We're trying to create a PowerPoint slide programmaticaly. We can obtain bullets on a single level, but playing with tabs and line returns doesn't work for nested enumerations.
For now we get:
- text 1
- subtext1
- subtext2
- text 2
And what we want is :
- text 1
- subtext1
- subtext2
- text 2
Is there a way to control these us开发者_如何转开发ing C# or VBA?
First, get a reference to the Paragraphs
of the TextRange2
, as each bulleted item is a paragraph (really a TextRange2
).
Dim pres As Presentation
Set pres = Application.ActivePresentation
Dim slide As slide
Set slide = pres.Slides(2)
Dim shapes As shapes
Set shapes = slide.shapes
Dim textShape As Shape
Set textShape = shapes(2)
Dim textFrame As TextFrame2
Set textFrame = textShape.TextFrame2
Dim textRng As TextRange2
Set textRng = textFrame.textRange
Dim p As TextRange2
Set p = textRng.Paragraphs
SetIndent 1, p.Item(1)
SetIndent 2, p.Item(2)
SetIndent 2, p.Item(3)
SetIndent 1, p.Item(4)
The last four lines call a function that encapsulates the logic of setting the indent "level," which affects the style of bullets and text, and the actual indent of the bullets and text:
Private Function SetIndent(ByVal level As Integer, ByRef p As TextRange2)
p.ParagraphFormat.IndentLevel = level
p.ParagraphFormat.FirstLineIndent = 40
p.ParagraphFormat.LeftIndent = level * 40
End Function
You could certainly refactor this to meet your needs -- like passing the indent factor (I hardcoded it as 40, but your mileage may vary).
精彩评论