Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #12  
Old 03-22-2021, 06:26 PM
macropod's Avatar
macropod macropod is offline How to script most table column in word document? Windows 10 How to script most table column in word document? 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
 

Tags
help please, most table column



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to add final touches to merged document, after running MailMergeToDoc script NicB Word VBA 1 09-02-2020 05:47 PM
How to generate a word document with a table-script valdavaux Word 1 09-17-2017 03:32 PM
Is it possible to put a formula in a table column header to define the name of the column? JacquesW Excel 3 05-08-2017 08:00 AM
VBA to search each row of a word table column Marrick13 Word VBA 7 11-17-2014 04:33 AM
How to script most table column in word document? two column word document. plato Word 1 08-06-2010 04:02 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:56 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft