Hi Serban:
You will notice that a List Template has a "Name" property. This is
mislabelled: it's not "The Name of the List Template", it's the "Name of the
ListNum fields sequence attached to this list template".
More importantly, it's not an index to the collection, so you cannot
retrieve a list template by the name attached to it.
However, when Margaret and Shauna and Bill Coan and I a few others were
playing around with this in the early days, we found we could attach a name
to the list template and it would stick.
We needed this in Word 97 and Word 2000, where the document would corrupt
and crash if the number of list templates got too high. Every time you
changed a list template or re-applied a style you would get a new list
template. In Word 2002 they put in a fix that would trim the number of list
templates in a document on Save, if the number was higher than 200. So now
we just ignore it. Call up the styles you want and just set the properties
of whichever list template is associated with each. If that creates some
extras, that won't matter until it gets above 200, when Word will
automatically trim them.
But here's some Word 97 code which shows how I worked around it:
' Define three List Template objects to contain our three lists
Dim HeadingList As ListTemplate
Dim NumberList As ListTemplate
Dim BulletList As ListTemplate
' When we enter this macro, we know we did not find the list
' template we were looking for, but we don't yet know if
' others do exist. This routine finds any that exist.
For i = 1 To ActiveDocument.ListTemplates.Count
Select Case ActiveDocument.ListTemplates(i).Name
Case Is = "OutlineHeadings"
Set HeadingList = ActiveDocument.ListTemplates(i)
Case Is = "OutlineNumbers"
Set NumberList = ActiveDocument.ListTemplates(i)
Case Is = "OutlineBullets"
Set BulletList = ActiveDocument.ListTemplates(i)
End Select
Next i
' Now we create any we did not find.
If HeadingList Is Nothing Then
Set HeadingList =
ActiveDocument.ListTemplates.Add(OutlineNumbered:=True)
HeadingList.Name = "OutlineHeadings"
End If
If NumberList Is Nothing Then
Set NumberList = ActiveDocument.ListTemplates.Add(OutlineNumbered:=True)
NumberList.Name = "OutlineNumbers"
End If
If BulletList Is Nothing Then
Set BulletList = ActiveDocument.ListTemplates.Add(OutlineNumbered:=True)
BulletList.Name = "OutlineBullets"
End If
Hope this helps
Hi John,
Thank you for your explanation. It makes very much sense that some class
definitions of default list templates are instantiated when the style
associated by default to them is used, maybe just to fill up some data
structures in the style object.
My "problem" was only about control (as I apply it when I am writing my own
code) so I will take your advice: live with it.
Best regards,
Serban
--
Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.
John McGhie <
[email protected]>
Microsoft MVP, Word and Word for Macintosh. Business Analyst, Consultant
Technical Writer.
Sydney, Australia +61 (0) 4 1209 1410