View Single Post
 
Old 09-14-2025, 04:01 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Code:
Sub QuerryAllTables()
Dim oTbl As Table
Dim oRng As Range
Dim oCell As Cell
  For Each oTbl In fcnCollectDocTables
    If oTbl.NestingLevel > 1 Then
      For Each oCell In oTbl.Range.Cells
        If Len(oCell.Range.Text) > 2 Then
          Debug.Print Left(oCell.Range.Text, Len(oCell.Range.Text) - 2)
        End If
      Next oCell
    End If
  Next
lbl_Exit:
  Exit Sub
End Sub

Function fcnCollectDocTables(Optional ByVal oDoc As Document) As Collection
'Returns all tables (top level and nested) in one collection.
Dim colStack As New Collection
Dim oTbl As Table
  Set fcnCollectDocTables = New Collection
  If Documents.Count > 0 And oDoc Is Nothing Then
    Set oDoc = ActiveDocument
  Else
    GoTo lbl_Exit
  End If
  colStack.Add oDoc.Tables
  Do While colStack.Count > 0
    For Each oTbl In colStack(1)
      fcnCollectDocTables.Add oTbl
      If oTbl.Tables.Count > 0 Then colStack.Add oTbl.Tables
    Next
    colStack.Remove 1
  Loop
lbl_Exit:
  Exit Function
End Function
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote