View Single Post
 
Old 07-16-2020, 05:17 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
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

Greg's code will identify tables with any merged cells but those may include horizontally merged cells.
This code will do what you asked but it uses the Selection object because I couldn't work out how to move a range down one cell.
Code:
Sub SplitVertMergeCells()
  Dim aTbl As Table, aCell As Cell, i As Integer, aRng As Range
  Dim iRow As Integer, iCol As Integer, iSplit As Integer
  For Each aTbl In ActiveDocument.Tables
    If Not aTbl.Uniform Then
      'Debug.Print "Table size: ", aTbl.Rows.Count, aTbl.Columns.Count
      For Each aCell In aTbl.Range.Cells
        'Debug.Print aCell.RowIndex, aCell.ColumnIndex
        If aCell.RowIndex = aTbl.Rows.Count Then Exit For
        Set aRng = aCell.Range
        aRng.Select
        Selection.MoveDown Unit:=wdLine, Count:=1
        If Selection.Information(wdWithInTable) Then
          iSplit = Selection.Cells(1).RowIndex - aRng.Cells(1).RowIndex
        Else
          iSplit = aTbl.Rows.Count - aRng.Cells(1).RowIndex + 1
        End If
        If iSplit > 1 Then aCell.Split NumRows:=iSplit
      Next aCell
    End If
  Next aTbl
End Sub
I'm hoping someone can improve on this to work without the selection object.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote