View Single Post
 
Old 08-11-2017, 03:11 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

The logic to add more than one row is essentially the same - you just need to extend the range being replicated to include those additional rows. ISTR posting code here some time ago to do something like that.

The code to replicate a table might be as simple as:
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
  With CCtrl
    Call TableDuplicate(.Range.Tables(1).Range)
  End With
End Sub

Sub TableDuplicate(RngSrc As Range)
Dim RngTgt As Range
With ActiveDocument
  On Error Resume Next
  With RngSrc
    With .Tables(1).Range.Duplicate
      .Collapse wdCollapseEnd
      .InsertAfter vbCr & vbCr
      Set RngTgt = .Characters.Last
    End With
  End With
  RngTgt.FormattedText = RngSrc.FormattedText
End With
Set RngTgt = Nothing
End Sub
Of course, you'd need to integrate that with the other code that checks whether you're in the right table, whether the user actually wants to add a new table and, if so, clear any content controls in the new table.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote