View Single Post
 
Old 03-22-2021, 06:26 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

If your document could potentially have tables with horizontally-merged cells, uneven cell widths in a column, or vertically-split cells, you need something like:
Code:
Sub TestTables()
Dim t As Long, c As Long, x As Long, y As Long, z As Long, StrTbls As String
With ActiveDocument
  For t = 1 To .Tables.Count
    With .Tables(t)
      If .Uniform = True Then
        z = .Columns.Count
        If z = x Then StrTbls = StrTbls & ", " & t
        If z > x Then x = z: StrTbls = t
      Else
        z = 0
        With .Range
          For c = 1 To .Cells.Count
            y = .Cells(c).ColumnIndex
            If y >= x Then z = y
          Next
        End With
        If z = x Then StrTbls = StrTbls & ", " & t
        If z > x Then x = z: StrTbls = t
      End If
    End With
  Next
End With
MsgBox "The most columns (" & x & ") are found in table(s): " & StrTbls
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote