Thread: [Solved] Code to add new row in table
View Single Post
 
Old 08-11-2022, 11:28 PM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,383
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

As written, the code checks whether it is exiting the last content control in the table. The number of content controls in that row is of no consequence. Indeed, the code was tested against tables having every possible kind of content control in a given row - including multiples of the same kind.

That said, it was not envisaged that the code would be run against a table having multiple content controls in the same cell. That could be accomodated by changing:
Code:
  'Get our ContentControl's index # in the table
  j = ActiveDocument.Range(.Range.Tables(1).Range.Start, .Range.End).ContentControls.Count
to:
Code:
  'Get our ContentControl's index # in the table
  j = ActiveDocument.Range(.Range.Tables(1).Range.Start, .Range.Cells(1).Range.Start).ContentControls.Count
  j = j + ActiveDocument.Range(.Range.Cells(1).Range.Start, .Range.End).ContentControls.Count
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote