Solved

VBA code to change numbering styles in existing Multilevel list

Posted on 2010-08-30
7
4,376 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:Fi69
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 9

Expert Comment

by:lwebber
ID: 33577612
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
 

Author Comment

by:Fi69
ID: 33583555
HI lwebber - the answer is B
0
 
LVL 9

Expert Comment

by:lwebber
ID: 33585248
Would it be OK to use the built-in Heading 1, Heading 2... styles? If not, what style name(s) are you using?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Accepted Solution

by:
Fi69 earned 0 total points
ID: 33585433
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
 

Author Comment

by:Fi69
ID: 33585438
By the way thanks for trying to help me!
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 33588000
Here is an article which explains List, and other,  numbering


http://word.mvps.org/faqs/numbering/WordsNumberingExplained.htm
0
 

Author Comment

by:Fi69
ID: 33592599
Thanks Graham

Shall have a read of this.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
Suggested Courses
Course of the Month4 days, 21 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question