View Single Post
 
Old 06-22-2023, 11:05 AM
David Peck David Peck is offline Windows 10 Office 2021
Novice
 
Join Date: Jun 2023
Posts: 3
David Peck is on a distinguished road
Default vba renumbering paragraph numbers each in top right cell of a series of table

I have a document with a series of tables containing a photo in the upper left cell and a description including a auto-numbered paragraph in the upper right cell.

I have used this code to insert the list number

With ListGalleries(wdNumberGallery).ListTemplates(1).Li stLevels(1)

Select Case Trim(gCapType)
Case "Photo"
.NumberFormat = "Photo %1:"
PrevCaptionType = "Photo"
Case "Figure"
.NumberFormat = "Figure %1:"
PrevCaptionType = "Figure"
Case "Illustration"
.NumberFormat = "Illustration %1:"
PrevCaptionType = "Illustration"
Case "Scan"
.NumberFormat = "Scan %1:"
PrevCaptionType = "Scan"
Case "User Specified"
'NEED CODE HERE TO HANDLE SPECIAL CASE
End Select

.TrailingCharacter = wdTrailingNone
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = InchesToPoints(0)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.5)
.TabPosition = wdUndefined
.ResetOnHigher = 0
'.StartAt = 1
.Font.Bold = True
.LinkedStyle = ""
End With

Selection.Range.ListFormat.ApplyListTemplate _
ListTemplate:=ListGalleries(wdNumberGallery).ListT emplates(1), _
ContinuePreviousList:=True, _
ApplyTo:=wdListApplyToSelection, _
DefaultListBehavior:=wdWord10ListBehavior

'UPDATE THE CAPTION NUMBER
Selection.Range.Fields.Update


the lists have no trouble renumbering when I delete a table from the sequence, but when insert a new table with its associated data in many circumstances it does not update the field with the new numbering.

I have tried several methods to update the field including reselecting each cell with an expected change and applying Selection.Range.Fields.Update

I have also tried looping through the fields in the fields collection.

Neither approach updates all of the cases for inserting before or after the originally selected table and at the boundary conditions for the beginning and ending of the section. A section break is used when the paragraph label changes (ie. "Photo:" to "Figure:")

Any suggestions for a way to force the renumbering to happen reliably would be welcome.
Reply With Quote