VBA code to change numbering styles in existing Multilevel list

Hi experts

I have a template in which I have set up several Multilevel lists linked to styles. My client now wants to be able to change the setup of one of these lists by running a macro. So for instance instead of
1.
1.1
(a)

Change this to
1.
(a)
(i)

This concept anyway.

In this list I have given a name of "ComplexNo2" to the ListNum field list_name.

I recorded my key strokes to change this list, but I'm concerned about running the code - how will it know what list to pick up and adjust? For instance the first line concerns me.
With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(1)
Right at the end there is
ListGalleries(wdOutlineNumberGallery).ListTemplates(1).Name = "ComplexNo2"
but I'm not sure how this comes into affect.

Is there a way to tell it which list, or should the recorded macro be fine to use?

Also, if anyone knows a good article to read on working with multilists with vba would appreciate the referral.


Sub RecordedMacro()
    With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(1)
        .NumberFormat = "%1"
        .TrailingCharacter = wdTrailingTab
        .NumberStyle = wdListNumberStyleNone
        .NumberPosition = CentimetersToPoints(0)
        .Alignment = wdListLevelAlignLeft
        .TextPosition = CentimetersToPoints(1)
        .TabPosition = CentimetersToPoints(1)
        .ResetOnHigher = 0
        .StartAt = 1
        With .Font
            .Bold = wdUndefined
            .Italic = wdUndefined
            .StrikeThrough = wdUndefined
            .Subscript = wdUndefined
            .Superscript = wdUndefined
            .Shadow = wdUndefined
            .Outline = wdUndefined
            .Emboss = wdUndefined
            .Engrave = wdUndefined
            .AllCaps = wdUndefined
            .Hidden = wdUndefined
            .Underline = wdUndefined
            .Color = wdUndefined
            .Size = wdUndefined
            .Animation = wdUndefined
            .DoubleStrikeThrough = wdUndefined
            .Name = ""
        End With
        .LinkedStyle = "Complex Numbering Level 1"
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(2)
        .NumberFormat = "%2%1."
        .TrailingCharacter = wdTrailingTab
        .NumberStyle = wdListNumberStyleArabic
        .NumberPosition = CentimetersToPoints(0)
        .Alignment = wdListLevelAlignLeft
        .TextPosition = CentimetersToPoints(1)
        .TabPosition = wdUndefined
        .ResetOnHigher = 1
        .StartAt = 1
        With .Font
            .Bold = False
            .Italic = False
            .StrikeThrough = False
            .Subscript = False
            .Superscript = False
            .Shadow = False
            .Outline = False
            .Emboss = False
            .Engrave = False
            .AllCaps = False
            .Hidden = False
            .Underline = wdUnderlineNone
            .Color = wdUndefined
            .Size = wdUndefined
            .Animation = wdUndefined
            .DoubleStrikeThrough = False
            .Name = "Times New Roman"
        End With
        .LinkedStyle = "Complex Numbering Level 2"
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(3)
        .NumberFormat = "(%3)"
        .TrailingCharacter = wdTrailingTab
        .NumberStyle = wdListNumberStyleLowercaseLetter
        .NumberPosition = CentimetersToPoints(0)
        .Alignment = wdListLevelAlignLeft
        .TextPosition = CentimetersToPoints(1.8)
        .TabPosition = CentimetersToPoints(0.8)
        .ResetOnHigher = 2
        .StartAt = 1
        With .Font
            .Bold = wdUndefined
            .Italic = wdUndefined
            .StrikeThrough = wdUndefined
            .Subscript = wdUndefined
            .Superscript = wdUndefined
            .Shadow = wdUndefined
            .Outline = wdUndefined
            .Emboss = wdUndefined
            .Engrave = wdUndefined
            .AllCaps = wdUndefined
            .Hidden = wdUndefined
            .Underline = wdUndefined
            .Color = wdColorAutomatic
            .Size = 8
            .Animation = wdUndefined
            .DoubleStrikeThrough = wdUndefined
            .Name = "Franklin Gothic Book"
        End With
        .LinkedStyle = "Complex Numbering Level 3"
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(4)
        .NumberFormat = "(%4)"
        .TrailingCharacter = wdTrailingTab
        .NumberStyle = wdListNumberStyleLowercaseRoman
        .NumberPosition = CentimetersToPoints(1.6)
        .Alignment = wdListLevelAlignLeft
        .TextPosition = CentimetersToPoints(2.2)
        .TabPosition = CentimetersToPoints(2.2)
        .ResetOnHigher = 3
        .StartAt = 1
        With .Font
            .Bold = wdUndefined
            .Italic = wdUndefined
            .StrikeThrough = wdUndefined
            .Subscript = wdUndefined
            .Superscript = wdUndefined
            .Shadow = wdUndefined
            .Outline = wdUndefined
            .Emboss = wdUndefined
            .Engrave = wdUndefined
            .AllCaps = wdUndefined
            .Hidden = wdUndefined
            .Underline = wdUndefined
            .Color = wdUndefined
            .Size = wdUndefined
            .Animation = wdUndefined
            .DoubleStrikeThrough = wdUndefined
            .Name = ""
        End With
        .LinkedStyle = "Complex Numbering Level 4"
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(5)
        .NumberFormat = "(%5)"
        .TrailingCharacter = wdTrailingTab
        .NumberStyle = wdListNumberStyleLowercaseLetter
        .NumberPosition = CentimetersToPoints(2.2)
        .Alignment = wdListLevelAlignLeft
        .TextPosition = CentimetersToPoints(2.8)
        .TabPosition = CentimetersToPoints(2.8)
        .ResetOnHigher = 4
        .StartAt = 1
        With .Font
            .Bold = wdUndefined
            .Italic = wdUndefined
            .StrikeThrough = wdUndefined
            .Subscript = wdUndefined
            .Superscript = wdUndefined
            .Shadow = wdUndefined
            .Outline = wdUndefined
            .Emboss = wdUndefined
            .Engrave = wdUndefined
            .AllCaps = wdUndefined
            .Hidden = wdUndefined
            .Underline = wdUndefined
            .Color = wdUndefined
            .Size = wdUndefined
            .Animation = wdUndefined
            .DoubleStrikeThrough = wdUndefined
            .Name = ""
        End With
        .LinkedStyle = "Complex Numbering Level 5"
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(6)
        .NumberFormat = ""
        .TrailingCharacter = wdTrailingTab
        .NumberStyle = wdListNumberStyleNone
        .NumberPosition = CentimetersToPoints(2.8)
        .Alignment = wdListLevelAlignLeft
        .TextPosition = CentimetersToPoints(4.42)
        .TabPosition = CentimetersToPoints(4.68)
        .ResetOnHigher = 5
        .StartAt = 1
        With .Font
            .Bold = wdUndefined
            .Italic = wdUndefined
            .StrikeThrough = wdUndefined
            .Subscript = wdUndefined
            .Superscript = wdUndefined
            .Shadow = wdUndefined
            .Outline = wdUndefined
            .Emboss = wdUndefined
            .Engrave = wdUndefined
            .AllCaps = wdUndefined
            .Hidden = wdUndefined
            .Underline = wdUndefined
            .Color = wdUndefined
            .Size = wdUndefined
            .Animation = wdUndefined
            .DoubleStrikeThrough = wdUndefined
            .Name = ""
        End With
        .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(7)
        .NumberFormat = ""
        .TrailingCharacter = wdTrailingTab
        .NumberStyle = wdListNumberStyleNone
        .NumberPosition = CentimetersToPoints(2.8)
        .Alignment = wdListLevelAlignLeft
        .TextPosition = CentimetersToPoints(5.31)
        .TabPosition = CentimetersToPoints(5.95)
        .ResetOnHigher = 6
        .StartAt = 1
        With .Font
            .Bold = wdUndefined
            .Italic = wdUndefined
            .StrikeThrough = wdUndefined
            .Subscript = wdUndefined
            .Superscript = wdUndefined
            .Shadow = wdUndefined
            .Outline = wdUndefined
            .Emboss = wdUndefined
            .Engrave = wdUndefined
            .AllCaps = wdUndefined
            .Hidden = wdUndefined
            .Underline = wdUndefined
            .Color = wdUndefined
            .Size = wdUndefined
            .Animation = wdUndefined
            .DoubleStrikeThrough = wdUndefined
            .Name = ""
        End With
        .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(8)
        .NumberFormat = ""
        .TrailingCharacter = wdTrailingTab
        .NumberStyle = wdListNumberStyleNone
        .NumberPosition = CentimetersToPoints(2.8)
        .Alignment = wdListLevelAlignLeft
        .TextPosition = CentimetersToPoints(6.2)
        .TabPosition = CentimetersToPoints(6.58)
        .ResetOnHigher = 7
        .StartAt = 1
        With .Font
            .Bold = wdUndefined
            .Italic = wdUndefined
            .StrikeThrough = wdUndefined
            .Subscript = wdUndefined
            .Superscript = wdUndefined
            .Shadow = wdUndefined
            .Outline = wdUndefined
            .Emboss = wdUndefined
            .Engrave = wdUndefined
            .AllCaps = wdUndefined
            .Hidden = wdUndefined
            .Underline = wdUndefined
            .Color = wdUndefined
            .Size = wdUndefined
            .Animation = wdUndefined
            .DoubleStrikeThrough = wdUndefined
            .Name = ""
        End With
        .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(9)
        .NumberFormat = ""
        .TrailingCharacter = wdTrailingTab
        .NumberStyle = wdListNumberStyleNone
        .NumberPosition = CentimetersToPoints(2.8)
        .Alignment = wdListLevelAlignLeft
        .TextPosition = CentimetersToPoints(7.22)
        .TabPosition = CentimetersToPoints(28)
        .ResetOnHigher = 8
        .StartAt = 1
        With .Font
            .Bold = wdUndefined
            .Italic = wdUndefined
            .StrikeThrough = wdUndefined
            .Subscript = wdUndefined
            .Superscript = wdUndefined
            .Shadow = wdUndefined
            .Outline = wdUndefined
            .Emboss = wdUndefined
            .Engrave = wdUndefined
            .AllCaps = wdUndefined
            .Hidden = wdUndefined
            .Underline = wdUndefined
            .Color = wdUndefined
            .Size = wdUndefined
            .Animation = wdUndefined
            .DoubleStrikeThrough = wdUndefined
            .Name = ""
        End With
        .LinkedStyle = ""
    End With
    ListGalleries(wdOutlineNumberGallery).ListTemplates(1).Name = "ComplexNo2"
    Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
        ListGalleries(wdOutlineNumberGallery).ListTemplates(1), _
        ContinuePreviousList:=False, ApplyTo:=wdListApplyToWholeList, _
        DefaultListBehavior:=wdWord10ListBehavior
End Sub

Open in new window

Fi69Asked:
Who is Participating?
 
Fi69Connect With a Mentor Author Commented:
Hi lwebber

After extensive search on the internet I finally stumbled across a solution today.  Here's the link:
http://www.eggheadcafe.com/aspnet_answers/wordnumbering/Aug2006/post27666622.asp
I've posted the code below too for convenience.

It is so hard to find anything on this subject.

Just a note on the code below - It is important that the multilevel list is named as I had done, ie "ComplexNo2".

Sub CreateListNumbering() 
 
Dim LT As ListTemplate 
 
Dim mylist As ListTemplate 
 
For Each LT In ActiveDocument.ListTemplates 
 
If LT.Name = "my list" Then 
 
Set mylist = LT 
 
Exit For 
 
End If 
 
Next LT 
 
If mylist Is Nothing Then 
 
Set mylist = ActiveDocument.ListTemplates.Add _ 
 
(OutlineNumbered:=True, Name:="my list") 
 
End If 
 
With mylist 
 
With .ListLevels(1) 
 
.NumberFormat = "%1." 
 
.TrailingCharacter = wdTrailingTab 
 
.NumberStyle = wdListNumberStyleArabic 
 
.NumberPosition = InchesToPoints(1) 
 
.Alignment = wdListLevelAlignLeft 
 
.TextPosition = InchesToPoints(1.25) 
 
.TabPosition = InchesToPoints(1.25) 
 
.ResetOnHigher = 0 
 
.StartAt = 1 
 
'Set a linked style: 
 
.LinkedStyle = "Heading 1" 
 
End With 
 
'Repeat With .ListLevels(n) 
 
'for n=2,...,9 
 
'and set the desired options 
 
'for each level 
 
End With 
 
End Sub 
 
Then use styles to apply numbering in the document. 
 
-- 
 
Stefan Blom 
 
Microsoft Word MVP 
 

Open in new window

0
 
lwebberCommented:
Tell me more about the styles. Let's just deal with your first numbering scheme for now (1., 1.1, (a)).

Two possibilities:

A. You want to use a single style name, like

    FooStyle

When you apply that style to a paragraph, it automatically gets the number 1. If you hit enter to get a new paragraph, that one gets the number 2. If you then hit  the Increase Indent button on the toolbar, it gets the number 1.1 (because the previous para is 1.), BUT the style name stays the same (FooStyle).

B. You have a set of styles called

    BarStyle 1
    BarStyle 2
    ...
    BarStyle 9

When you apply the BarStyle 1 to a paragraph, it automaticallly gets the number 1. If you hit enter to get a new paragraph, that one gets the number 2. If you then hit  the Increase Indent button on the toolbar, it gets the number 1.1 (because the previous para is 1.), AND ITS STYLE NAME AUTOMATICALLY changes to BarStyle 2.

Scenario B is similar to the built-in styles called Heading 1, Heading 2, etc.

Your choice of A or B will determine the answer to your question.
0
 
Fi69Author Commented:
HI lwebber - the answer is B
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
lwebberCommented:
Would it be OK to use the built-in Heading 1, Heading 2... styles? If not, what style name(s) are you using?
0
 
Fi69Author Commented:
By the way thanks for trying to help me!
0
 
GrahamSkanRetiredCommented:
Here is an article which explains List, and other,  numbering


http://word.mvps.org/faqs/numbering/WordsNumberingExplained.htm
0
 
Fi69Author Commented:
Thanks Graham

Shall have a read of this.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.