View Single Post
 
Old 05-06-2024, 04:43 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Hi Greg

I've had a look at your code and will throw in a bit of biased keyboard warrior opinion to add to the mix. I do have several macros like this that I've been using in templates for a very long time and can highly recommend them because lists have a well justified reputation for fragility. A macro like yours instantly fixes the style series should the list develop a problem.

I am not a fan of adding new custom styles when there is already 250+ built-in style names which you can't get rid of especially when two series exist pretty much for this exact list type. For instance, I would prefer to use the 'List Multi' or 'List' series for a list like the one you are configuring. Using the built-in style name is cleaner (IMO), and you don't need extra code to check it exists. Although those built-in names only go up to 5, you could either add some custom ones for 6-9 or just not associate those lowest levels with a style (like I do). The chance of needing a list out to 6+ levels is pretty low so I normally leave the linked style blank for those ones. You can still apply the extra list levels by outline demote (Alt-Shift-Right Arrow) so having a paragraph style for it as well doesn't serve much usefulness.

You asked about modifying the List Gallery - if you want to do that, you can avoid the clumsiness of the List style competely and cut out nearly all of the preamble...
Code:
Dim oLT As ListTemplate  
  Set oLT = ListGalleries(wdOutlineNumberGallery).ListTemplates(1)
  With oLT
[[Relevant only if you ignore my above rant on custom styles]] It might be easy to trip people by giving them a chance to edit the list prefix constant (without telling them it had to be three characters). Your cleanup macro is looking for a three character prefix only. Perhaps rewrite that line to allow for any matching prefix
Code:
If oStyle.NameLocal Like m_strStyleLevelPrefixName & "*" Or oStyle.NameLocal = m_strListStyleName Then
And here is a little bit of code in case you wanted to audit what list templates are already in your document.
Code:
Sub CompileAllListTemplates()
  Dim aLT As ListTemplate, i As Integer
  For Each aLT In ListGalleries(wdOutlineNumberGallery).ListTemplates
    Debug.Print aLT.Name, aLT.ListLevels(1).LinkedStyle
  Next aLT
  Debug.Print "=-=-=-=-=-=-=--"
  For Each aLT In ActiveDocument.ListTemplates
    If aLT.OutlineNumbered Then
      'i = i + 1
      'If aLT.Name = "" Then aLT.Name = "ListTemp" & i
      Debug.Print aLT.Name, aLT.ListLevels(1).LinkedStyle
    End If
  Next aLT
  ''rename a list template
'  ActiveDocument.ListTemplates("ListTemp19").Name = "Callout"
'  ActiveDocument.ListTemplates("ListBullet").Name = "List Bullet"
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote