Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-22-2023, 11:05 AM
David Peck David Peck is offline vba renumbering paragraph numbers each in top right cell of a series of table Windows 10 vba renumbering paragraph numbers each in top right cell of a series of table Office 2021
Novice
vba renumbering paragraph numbers each in top right cell of a series of table
 
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
  #2  
Old 06-22-2023, 04:31 PM
Guessed's Avatar
Guessed Guessed is offline vba renumbering paragraph numbers each in top right cell of a series of table Windows 10 vba renumbering paragraph numbers each in top right cell of a series of table Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,978
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
Reply

Tags
renumber para # fields



Similar Threads
Thread Thread Starter Forum Replies Last Post
table cell values to another word document paragraph abonsey Word VBA 3 06-16-2022 04:36 AM
vba renumbering paragraph numbers each in top right cell of a series of table Why do numbers show up a little lower in table cell? HealthyStealthy Word 2 09-06-2016 06:36 AM
Replace 0000s with a series of numbers tingker Word VBA 2 12-17-2014 06:06 AM
vba renumbering paragraph numbers each in top right cell of a series of table Moving up/ down a paragraph within a Table Cell by using keyboard Joey Cheung Word Tables 1 08-12-2014 05:19 PM
Remove Paragraph numbers from Table of Co Bu_zz2020 Word 3 08-27-2013 08:49 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft