VBA Code


What is a ListGallery

There are three types of list galleries in Word:

  • wdBulletGallery - Single Level Bullets

  • wdNumberGallery - Single Level Numbered

  • wdOutlineNumberGallery - Multi-Level Numbering

ListGalleries are saved at both the application level and at the document level.
At the application level there can be only 7 different list templates for each of the 3 tabs.

Application.ListGalleries(wdListGalleryType.wdBulletGallery).ListTemplates 
Application.ListGalleries(wdListGalleryType.wdNumberGallery).ListTemplates
Application.ListGalleries(wdListGalleryType.wdOutlineNumberGallery).ListTemplates

At the document (or template) level there can be any number of different list templates.

ActiveDocument.ListTemplates() 

Single Level Bullets - wdBulletGallery


If Application.ListGalleries(wdListGalleryType.wdBulletGallery).Modified(1) = True Then 
   Application.ListGalleries(wdListGalleryType.wdBulletGallery).Reset 1
End If
Application.ListGalleries(wdListGalleryType.wdBulletGallery).Reset 7

This type of bullet only has Listlevel(1)

With Application.ListGalleries(wdListGalleryType.wdBulletGallery) 
   .ListTemplates(1).ListLevels(1).Font.Name = "Symbol"
   .ListTemplates(1).ListLevels(1).NumberFormat = ChrW(61623)
   .ListTemplates(1).ListLevels(1).NumberStyle = wdListNumberStyle.wdListNumberStyleBullet

   .ListTemplates(2).ListLevels(1).Font.Name = "Courier New"
   .ListTemplates(2).ListLevels(1).NumberFormat = "o"

   .ListTemplates(3).ListLevels(1).Font.Name = "Wingdings"
   .ListTemplates(3).ListLevels(1).NumberFormat = ChrW(61607)

   .ListTemplates(4).ListLevels(1).ApplyPictureBullet FileName:=DefaultPictureBullet
'.ListTemplates(4).ListLevels(1).ApplyPictureBullet FileName:= "C:\Temp\my_image.bmp"

   .ListTemplates(5).ListLevels(1).Font.Name = "Wingdings"
   .ListTemplates(5).ListLevels(1).NumberFormat = ChrW(61558)

   .ListTemplates(6).ListLevels(1).Font.Name = "Wingdings"
   .ListTemplates(6).ListLevels(1).NumberFormat = ChrW(61656)

   .ListTemplates(7).ListLevels(1).Font.Name = "Wingdings"
   .ListTemplates(7).ListLevels(1).NumberFormat = ChrW(61692)
End With


Single Level Numbered - wdNumberGallery


If Application.ListGalleries(wdListGalleryType.wdNumberGallery).Modified(1) = True Then 
   Application.ListGalleries(wdListGalleryType.wdNumberGallery).Reset 1
End If
Application.ListGalleries(wdListGalleryType.wdNumberGallery).Reset 7

List Number - You can get the number that has been applied to any list-numbered paragraph using the ListString property

Selection.Paragraphs(1).Range.ListFormat.ListString 

List Level - This means the level in a numbering outline. You can get the list level that has been applied to any list-numbered paragraph using the ListLevelNumber property

Selection.Paragraphs(1).Range.ListFormat.ListLevelNumber 

A paragraph that has no list numbering applied to it returns 1 (instead of 0).
One way of distinguishing unnumbered from numbered paragraphs that genuinely have a list level of 1 is to check how many listparagraphs are in the current range

If Selection.Paragraphs(1).Range.ListParagraphs.Count = 1 Then 
   If (Selection.Paragraphs(1).Range.ListFormat.ListLevelNumber = 1) Then
'this is a genuine numbered paragraph
   End If
End If


This type of bullet only has Listlevel(1)

With Application.ListGalleries(wdListGalleryType.wdBulletGallery) 
   .ListTemplates(1).ListLevels(1).NumberFormat = "%1."
   .ListTemplates(1).ListLevels(1).NumberStyle = wdListNumberStyle.wdListNumberStyleArabic

   .ListTemplates(2).ListLevels(1).NumberFormat = "%1)"
   .ListTemplates(2).ListLevels(1).NumberStyle = wdListNumberStyle.wdListNumberStyleLowercaseLetter

   .ListTemplates(3).ListLevels(1).NumberFormat = "%1."
   .ListTemplates(3).ListLevels(1).NumberStyle = wdListNumberStyle.wdListNumberStyleUppercaseRoman

   .ListTemplates(4).ListLevels(1).NumberFormat = "%1."
   .ListTemplates(4).ListLevels(1).NumberStyle = wdListNumberStyle.wdListNumberStyleUppercaseLetter

   .ListTemplates(5).ListLevels(1).NumberFormat = "%1)"
   .ListTemplates(5).ListLevels(1).NumberStyle = wdListNumberStyle.wdListNumberStyleLowercaseLetter

   .ListTemplates(6).ListLevels(1).NumberFormat = "%1."
   .ListTemplates(6).ListLevels(1).NumberStyle = wdListNumberStyle.wdListNumberStyleLowercaseLetter

   .ListTemplates(7).ListLevels(1).NumberFormat = "%1."
   .ListTemplates(7).ListLevels(1).NumberStyle = wdListNumberStyle.wdListNumberStyleLowercaseRoman
End With

Multi-Level Numbering - wdOutlineNumberGallery


If Application.ListGalleries(wdListGalleryType.wdOutlineNumberGallery).Modified(1) = True Then 
   Application.ListGalleries(wdListGalleryType.wdOutlineNumberGallery).Reset 1
End If
Application.ListGalleries(wdListGalleryType.wdOutlineNumberGallery).Reset 9

With Application.ListGalleries(wdListGalleryType.wdOutlineNumberGallery) 
   .ListTemplates(1).ListLevels(1)
   .ListTemplates(1).ListLevels(2)
   .ListTemplates(1).ListLevels(3)
   .ListTemplates(1).ListLevels(4)
   .ListTemplates(1).ListLevels(5)
   .ListTemplates(1).ListLevels(6)
   .ListTemplates(1).ListLevels(7)
   .ListTemplates(1).ListLevels(8)
   .ListTemplates(1).ListLevels(9)
End With


      .TrailingCharacter = wdTrailingCharacter.wdTrailingTab 
      .NumberPosition = CentimetersToPoints(0)
      .Alignment = wdListLevelAlignment.wdListLevelAlignLeft
      .TextPosition = CentimetersToPoints(1)
      .TabPosition = CentimetersToPoints(2)
      .ResetOnHigher = 0
      .StartAt = 1
      .LinkedStyle = "Date"

Selection.Range.ListFormat.ListType = wdListType.wdListBullet 


Outline Numbering

Selection.Paragraphs(1).OutlineLevel 


Dim oListFormat As ListFormat 
Dim oListTemplate As ListTemplate
Dim oListLevel As ListLevel

Set oListFormat = Selection.Paragraphs(1).Range.ListFormat
'Debug.Print oListFormat.ListLevelNumber
'Debug.Print oListFormat.ListString
Set oListTemplate = oListFormat.ListTemplate
'Debug.Print oListTemplate.ListLevels.Count
Set oListLevel = oListTemplate.ListLevels.Item(oListFormat.ListLevelNumber)
Debug.Print oListLevel.NumberStyle = wdListNumberStyleBullet
Debug.Print oListLevel.Font.Name
Debug.Print oListLevel.NumberFormat
Debug.Print oListLevel.NumberPosition
Stop

Debug.Print Application.ListGalleries(wdBulletGallery).ListTemplates.Count
Stop


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext