View Single Post
 
Old 09-10-2025, 04:54 PM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
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

For example:
Code:
Sub Demo()
Dim Tbl As Table, Cll As Cell, Rng As Range
For Each Tbl In ActiveDocument.Tables
  With Tbl
    For Each Cll In .Range.Cells
      Set Rng = Cll.Range: Rng.End = Rng.End - 1
      If Rng.Cells(1).NestingLevel > 1 Then
        With Rng
          MsgBox .Text
          .End = .End - 2: .Start = .Characters.Last.Cells(1).Range.Start
          MsgBox .Text
        End With
      End If
    Next
  End With
Next
End Sub
But this only works if there is no other content in the parent cell.

Alternatively, you could use:
Code:
Sub Demo()
Dim Tbl As Table, Cll As Cell
For Each Tbl In ActiveDocument.Tables
  With Tbl
    For Each Cll In .Range.Cells
      With Cll.Range
        If .Cells(1).Tables.Count > 0 Then
          With .Cells(1).Tables(1).Range
            MsgBox .Text
            .End = .End - 2: .Start = .Characters.Last.Cells(1).Range.Start
            MsgBox .Text
          End With
        End If
      End With
    Next
  End With
Next
End Sub
which works even if there is other content in the parent cell.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote