Christopher Greaves

Contact Me

ON LINE STORE

ON LINE STORE

ON LINE STORE

ON LINE STORE

List Numbering in Microsoft Word

The Nature Of The Problem ; Reading List ; List Numbering Is Broken ; Terminology ; Styles ; What Have We Got Here? ; Isolating A List Template ; Manipulating List Templates ; Review Of Outline Numbered List Templates ; Locating List Templates ; Removing Named List Templates ; What About The Other Two List Galleries? ; Creating Extra List Templates ; List Templates In The Document ; Making A Fresh Start ; Purge List Gallery History ; Ferreting out List Templates ; Review Of List Templates ; An Experiment With Simple Numbered List Templates ; A Built-In Numbered Simple List ; Using Named List Templates ; Steps To Build A Named List Template ; Structures ; Assembling The Style ; Assembling A List Template ; Checking It Out ; Locating A Named List Template ; Deleting List Templates ; Paste To New Document

If you are interested in applications please visit www.VBASolutions.ca .

If you are interested in end-user macros please visit www.TorontoMacros.com .

Isolating A List Template

We will continue to use some simple VBA to explore our current system.

The code samples here were tested on Word 2000; they should function well on later versions of Word, and may well function on Word 97.

Remember that all our systems are by now different; the example screen shots here may not match your system because you have spent efforts on creating List Templates that differ from my efforts.

Sub TESTListTemplates()

Call DisplayListTemplates(Application.ListGalleries(wdBulletGallery))

Call DisplayListTemplates(Application.ListGalleries(wdNumberGallery))

Call DisplayListTemplates(Application.ListGalleries(wdOutlineNumberGallery))

End Sub

Public Function DisplayListTemplates(lstG As ListGallery)

Dim lng As Long

For lng = 1 To 7

Debug.Print lng & vbTab & "Name: " & vbTab & "*" & lstG.ListTemplates(lng).Name & "*"

Next lng

End Function

The macro above should display the names of the List templates in each of the three specific List Galleries.

Note that List templates are numbered starting at One.

1 name: **

2 name: **

3 name: **

4 name: **

5 name: **

6 name: **

7 name: **

1 name: **

2 name: **

3 name: **

4 name: **

5 name: **

6 name: **

7 name: **

1 name: **

2 name: **

3 name: *Greaves2*

4 name: **

5 name: **

6 name: *gREAVES1*

7 name: **

The results are as we expected, very similar to our previous display.

I have embraced the names in asterisks to make clarify their appearance.

You can see that the two named List Templates have exactly eight characters each in their names- no trailing spaces!

Now let’s explore a little further.

Let’s refer to a specific List Gallery (by the Word constant “wdOutlineNumberGallery”) and let’s refer to a specific List Template (3) within that List Gallery

Sub TESTListTemplates2()

Dim lstG As ListGallery

Set lstG = Application.ListGalleries(wdOutlineNumberGallery)

Debug.Print "Name: " & vbTab & "*" & lstG.ListTemplates(3).Name & "*"

End Sub

Here is what I see:

Name: *Greaves2*

So far so good. Based on my previous example, I expected to see “Greaves2” as the name of the 3rd List Template in the List Gallery known as wdOutlineNumberGallery.

Since the List Template has a name, you’d expect to be able to refer to it by its name:

Sub TESTListTemplates3()

Dim lstG As ListGallery

Set lstG = Application.ListGalleries(wdOutlineNumberGallery)

Debug.Print "Name: " & vbTab & "*" & lstG.ListTemplates("Greaves2").Name & "*"

End Sub

Nope! This macro generates a run-time error 5941 – The requested member of the collection does not exist.

Can we locate the List Template within the List Gallery?

Public Function lngListTemplateIndex(lstG As ListGallery, strName As String) As Long

lngListTemplateIndex = -1 ' default result is failure

Dim lng As Long

For lng = 1 To lstG.ListTemplates.Count

If lstG.ListTemplates(lng).Name = strName Then

lngListTemplateIndex = lng

Exit For

Else

End If

Next lng

End Function

Sub TESTlngListTemplateIndex()

Dim lstG As ListGallery

Set lstG = Application.ListGalleries(wdOutlineNumberGallery)

Debug.Print lngListTemplateIndex(lstG, "Greaves2")

End Sub

Yes!

3

How Odd! Yet it’s not the first time I’ve met a collection that permits indexing by number but not by name.

Manipulating List Templates

Contact Me