Christopher Greaves |
|||
Christopher Greaves |
|||
If you are interested in applications please visit www.VBASolutions.ca .
If you are interested in end-user macros please visit www.TorontoMacros.com .
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
Note that List templates are numbered starting at One.
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: **
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
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
Can we locate the List Template within the List Gallery?
Public Function lngListTemplateIndex(lstG As ListGallery, strName As String) As LonglngListTemplateIndex = -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