Restarting list numbering using a higher level style
Article contributed by Margaret Aldis
This article covers how to restart list numbering using a paragraph at a higher level in the same outline numbering scheme. This method is very reliable but it needs to be 'designed in' - it cannot be used on existing documents without making changes to styles. For other methods of restarting list numbering, see How to restart style-based numbering.
The first step is to decide on the style hierarchy. Start by looking at the logical structure of the document to see if there is already a style that can be used to restart the list numbering. For example, if you are writing numbered procedural steps and each procedure starts with a procedure title, you can restart numbering of procedure steps after the procedure title style. Remember the intervening style does not have to come immediately before or after a list, just so long as the same style reliably intervenes - you could even use Body Text style, if you know that you will always have intervening Body Text paragraphs between lists.
If you cannot be certain that any particular style will separate lists, or if you don't want to include a heavily used style like Body Text in a numbering scheme, then you can set up a dummy style at the top level, with formatting to prevent it appearing in the final print. Using a dummy style means you will need to include a dummy paragraph at the start of each list, and so the style formatting needs to be chosen carefully to minimize the possibilities of turning real text 'invisible', and to maximize ease of editing. A good solution for a printed document is to use a framed style, with the frame placed in the margin, and the font set to a bright colour. Provided editing is done with Show/Hide showing non-printing characters, the empty paragraph then displays as a coloured paragraph symbol, does not disturb page layout, and is easy to select. A framed style will not work if you need to save the document as a Web page, however, and you would also need to check compatibility of this approach with any third party conversion tools you use such as online Help creation software.
When you have decided on the hierarchy, set up the styles and the numbering scheme. You can do this manually, working from the top-level style, or use VBA code as shown in the example below.
If you are using the logical structure of the document to restart lists, then once you have set up the styles your list numbering will work reliably and silently without any further user intervention. If you are using a dummy style, then whenever you start a new list you must insert a paragraph in this style. This can be automated very simply by using an AutoText for the dummy paragraph, and making sure the follow-on style is set to the list item style, so that pressing return after inserting the AutoText automatically creates the first item. For a wider user base it's worth being a bit more sophisticated with macros, to include converting selected paragraphs to a new list. You can also provide a 'continue numbering' macro to remove the next previous dummy paragraph, so users do not need to understand the mechanism.
Example VBA code to set up numbered list
The following example sets up a dummy style and three levels of numbered list. Note that this code does not need to be present in the final document or template, as it is only used at design stage, while setting up the styles.
Sub SetUpNumberedLists()
' Sets up built-in numbered list styles and List Template
' including restart paragraph style
' Run in document template during design
' Macro created by Margaret Aldis, Syntagma
'
' Create list starting style and format if it doesn't already exist
Dim strStyleName As String
strStyleName = "ListStart" ' the style name in this set up
Dim strListTemplateName As String
strListTemplateName = "items" ' the list template name in this set up
Dim astyle As Style
For Each astyle In ActiveDocument.Styles
If astyle.NameLocal = strStyleName Then GoTo Define 'already exists
Next astyle
' doesn't exist
ActiveDocument.Styles.Add Name:=strStyleName, Type:=wdStyleTypeParagraph
Define:
With ActiveDocument.Styles(strStyleName)
.AutomaticallyUpdate = False
.BaseStyle = ""
.NextParagraphStyle = wdStyleListNumber 'international compatibility
End With
With ActiveDocument.Styles(strStyleName).Font
.Size = 9
.ColorIndex = wdViolet
End With
With ActiveDocument.Styles(strStyleName).ParagraphFormat
.LineSpacingRule = wdLineSpaceSingle
.WidowControl = False
.KeepWithNext = True
.KeepTogether = True
.OutlineLevel = wdOutlineLevelBodyText
End With
With ActiveDocument.Styles(strStyleName).Frame
.TextWrap = True
.WidthRule = wdFrameAuto
.HeightRule = wdFrameAuto
.HorizontalPosition = CentimetersToPoints(- 1 )
.RelativeHorizontalPosition = wdRelativeHorizontalPositionColumn
.VerticalPosition = CentimetersToPoints( 0 )
.RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
.HorizontalDistanceFromText = CentimetersToPoints( 0 )
.VerticalDistanceFromText = CentimetersToPoints( 0 )
.LockAnchor = False
End With
' Create the list template if it doesn't exist
Dim aListTemplate As ListTemplate
For Each aListTemplate In ActiveDocument.ListTemplates
If aListTemplate.Name = strListTemplateName Then GoTo Format 'already exists
Next aListTemplate
' doesn't exist
Dim newlisttemplate As ListTemplate
Set newlisttemplate = ActiveDocument.ListTemplates _
.Add(OutlineNumbered:= True , Name:= "items" )
Format:
' Set up starter and three list levels - edit/extend from recorded details if required
With ActiveDocument.ListTemplates(strListTemplateName).ListLevels( 1 )
.NumberFormat = ""
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleNone
.NumberPosition = CentimetersToPoints( 0 )
.Alignment = wdListLevelAlignLeft
.TextPosition = CentimetersToPoints(- 0 . 5 )
.TabPosition = CentimetersToPoints( 0 )
.ResetOnHigher = True
.StartAt = 1
.LinkedStyle = strStyleName
End With
With ActiveDocument.ListTemplates(strListTemplateName).ListLevels( 2 )
.NumberFormat = "%2"
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = CentimetersToPoints( 0 )
.Alignment = wdListLevelAlignLeft
.TextPosition = CentimetersToPoints( 0 . 5 )
.TabPosition = CentimetersToPoints( 0 . 5 )
.ResetOnHigher = True
.StartAt = 1
With .Font
.Bold = True
End With
.LinkedStyle = ActiveDocument.Styles(wdStyleListNumber).NameLocal
End With
With ActiveDocument.ListTemplates(strListTemplateName).ListLevels( 3 )
.NumberFormat = "%3"
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleLowercaseLetter
.NumberPosition = CentimetersToPoints( 0 . 5 )
.Alignment = wdListLevelAlignLeft
.TextPosition = CentimetersToPoints( 1 )
.TabPosition = CentimetersToPoints( 1 )
.ResetOnHigher = True
.StartAt = 1
With .Font
.Bold = True
End With
.LinkedStyle = ActiveDocument.Styles(wdStyleListNumber2).NameLocal
End With
With ActiveDocument.ListTemplates(strListTemplateName).ListLevels( 4 )
.NumberFormat = "%4"
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleLowercaseRoman
.NumberPosition = CentimetersToPoints( 1 )
.Alignment = wdListLevelAlignLeft
.TextPosition = CentimetersToPoints( 1 . 5 )
.TabPosition = CentimetersToPoints( 1 . 5 )
.ResetOnHigher = True
.StartAt = 1
With .Font
.Bold = True
End With
.LinkedStyle = ActiveDocument.Styles(wdStyleListNumber3).NameLocal
End With
With ActiveDocument.ListTemplates(strListTemplateName).ListLevels( 5 )
.NumberFormat = ""
.LinkedStyle = ""
End With
With ActiveDocument.ListTemplates(strListTemplateName).ListLevels( 6 )
.NumberFormat = ""
.LinkedStyle = ""
End With
With ActiveDocument.ListTemplates(strListTemplateName).ListLevels( 7 )
.NumberFormat = ""
.LinkedStyle = ""
End With
With ActiveDocument.ListTemplates(strListTemplateName).ListLevels( 8 )
.NumberFormat = ""
.LinkedStyle = ""
End With
With ActiveDocument.ListTemplates(strListTemplateName).ListLevels( 9 )
.NumberFormat = ""
.LinkedStyle = ""
End With
End Sub