Outline Numbering via VBA

L

Lee

I used VBA to set up List Number 0- List Number 3 outline
numbering styles. 1 and 3 work perfectly. However, List
Number 2 is not exactly indenting correctly. The hanging
text indents correctly. But, the number and the text are
right next to each other until the list reaches 10 or
greater. This happens no matter how much of an indent I
use.

Code follows. Any suggestions would be helpful.

Thank you!
Lee

Sub SetupListNumbering()
'
'
Dim oLstTemplate As ListTemplate, TemplateFound As Boolean
'-------------------------------------------------
'-------------------------------------------------
'Find or Create List 0
bFound = False
For Each MyStyle In ActiveDocument.Styles
If MyStyle.NameLocal = "List Number 0" Then
bFound = True
End If
Next MyStyle
If Not (bFound) Then
ActiveDocument.Styles.Add Name:="List Number 0",
Type:=wdStyleTypeParagraph
End If
'-------------------------------------------------
'-------------------------------------------------
'Then SET UP THE STYLES
With ActiveDocument.Styles("List Number 0")
.AutomaticallyUpdate = False
.BaseStyle = "Normal"
.NextParagraphStyle = "List Number"
With .ParagraphFormat
.SpaceAfter = 0
.SpaceBefore = 0
.LeftIndent = 0
.RightIndent = 0
.HangingPunctuation = True
.KeepWithNext = True
.LineSpacingRule = wdLineSpaceSingle
End With
.Font.Size = 1
End With
'-------------------------------------------------
With ActiveDocument.Styles("List Number")
.AutomaticallyUpdate = False
.BaseStyle = "Normal"
.NextParagraphStyle = "List Number"
With .ParagraphFormat
.SpaceAfter = 6
.SpaceBefore = 0
.LeftIndent = 0
.RightIndent = 0
.HangingPunctuation = True
.KeepWithNext = True
.LineSpacingRule = wdLineSpaceSingle
End With
End With
'-------------------------------------------------
With ActiveDocument.Styles("List Number 2")
.AutomaticallyUpdate = False
.BaseStyle = "List Number"
.NextParagraphStyle = "List Number 2"
With .ParagraphFormat
.SpaceAfter = 6
.SpaceBefore = 0
.LeftIndent = 0
.RightIndent = 0
.HangingPunctuation = True
.KeepWithNext = True
.LineSpacingRule = wdLineSpaceSingle
End With
End With
'-------------------------------------------------
With ActiveDocument.Styles("List Number 3")
.AutomaticallyUpdate = False
.BaseStyle = "List Number 2"
.NextParagraphStyle = "List Number 3"
With .ParagraphFormat
.SpaceAfter = 6
.SpaceBefore = 0
.LeftIndent = 0
.RightIndent = 0
.HangingPunctuation = True
.KeepWithNext = True
.LineSpacingRule = wdLineSpaceSingle
End With
End With
'-------------------------------------------------
With ActiveDocument.Styles("List Number 4")
.AutomaticallyUpdate = False
.BaseStyle = "List Number 3"
.ParagraphFormat.SpaceAfter = 6
.ParagraphFormat.HangingPunctuation = True
End With
'----------------------------------------------------------
------
'----------------------------------------------------------
------
'THEN FIND OR CREATE THE LIST TEMPLATE
For Each oLstTemplate In ActiveDocument.ListTemplates
If oLstTemplate.Name = "ListNumberTemplate" Then
TemplateFound = True
Exit For
End If
Next oLstTemplate
'----------------------------------------------------------
------
If TemplateFound Then
Set oLstTemplate = ActiveDocument.ListTemplates
("ListNumberTemplate")
Else
Set oLstTemplate = ActiveDocument.ListTemplates.Add
(OutlineNumbered:=True)
oLstTemplate.Name = "ListNumberTemplate"
End If
'----------------------------------------------------------
------
'----------------------------------------------------------
------
'THEN DEFINE THE LIST TEMPLATE
With oLstTemplate.ListLevels(1)
.NumberFormat = ""
.TrailingCharacter = wdTrailingNone
.NumberStyle = wdListNumberStyleLegal
.NumberPosition = InchesToPoints(0)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.35)
.TabPosition = wdUndefined
.ResetOnHigher = True
.StartAt = 1
.LinkedStyle = "List Number 0"
End With
'-------------------------------------------------
With oLstTemplate.ListLevels(2)
.NumberFormat = "%2."
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = InchesToPoints(0.4)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.65)
.TabPosition = wdUndefined
.ResetOnHigher = True
.StartAt = 1
.LinkedStyle = "List Number"
End With
'-------------------------------------------------
With oLstTemplate.ListLevels(3)
.NumberFormat = "%3."
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = InchesToPoints(0.85)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(1.15)
.TabPosition = wdUndefined
.ResetOnHigher = True
.StartAt = 1
.LinkedStyle = "List Number 2"
End With
'-------------------------------------------------
With oLstTemplate.ListLevels(4)
.NumberFormat = "%4."
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = InchesToPoints(1.45)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(1.7)
.TabPosition = wdUndefined
.ResetOnHigher = True
.StartAt = 1
.LinkedStyle = "List Number 3"
End With
'-------------------------------------------------
With oLstTemplate.ListLevels(5)
.NumberFormat = ""
.TrailingCharacter = wdTrailingNone
.NumberStyle = wdListNumberStyleNone
.NumberPosition = InchesToPoints(1.4)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(2.4)
.TabPosition = wdUndefined
.ResetOnHigher = True
.StartAt = 1
.LinkedStyle = "List Number 4"
End With
End Sub
 
S

Suzanne S. Barnhill

In the Numbering dialog, you can set a position for the hanging indent and
tab position (which ordinarily will be the same). You need to allow more
space here; note that this *must* be done through the Numbering dialog, not
the Paragraph dialog.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://www.mvps.org/word
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
L

Lee

Thanks, Suzanne. I set the tab position equal to the text
position and that fixed it :~)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top