View Single Post
 
Old 06-22-2023, 04:31 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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

Note that normally the built-in functionality of captions in Word use Seq fields and not list templates. So I'm not really confident that I understand what the purpose of your code is. So take the following suggestions as only recommendations - you may have other things going on that I am not taking into account.

Automatic numbering with the ListGalleries are NOT fields so updating a range of fields won't change those list numbers (but might update some cross-references to them). If you want to reset the list numbers then you should link a to style and then refresh the paragraph attributes of the selection.

I note when you ApplyListTemplate you are applying it to only the Selection so there is a flag that says this won't apply to non-selected paragraphs that used the same ListTemplate.

FWIW, your Select Case section seems like overkill unless the "User Specified" option is going to be treated differently. You could simplify your code along these lines.
Code:
  With ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1)
    PrevCaptionType = Trim(gCapType)
    .NumberFormat = PrevCaptionType & " %1:"
    .TrailingCharacter = wdTrailingNone
    .NumberStyle = wdListNumberStyleArabic
    .NumberPosition = InchesToPoints(0)
    .Alignment = wdListLevelAlignLeft
    .TextPosition = InchesToPoints(0.5)
    .TabPosition = wdUndefined
    .ResetOnHigher = 0
    '.StartAt = 1
    .Font.Bold = True
    .LinkedStyle = ""   'you should use this
  End With
  
  Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries(wdNumberGallery).ListTemplates(1), _
        ContinuePreviousList:=True, ApplyTo:=wdListApplyToSelection, DefaultListBehavior:=wdWord10ListBehavior
  
  'UPDATE THE CAPTION NUMBER
  Selection.Range.Fields.Update             'this updates fields
  Selection.Range.ParagraphFormat.Reset     'this updates listnumbers which are linked to styles
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote