Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Apr 2003
    Location
    Kansas City, Missouri
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Detecting Nested Tables (Word 200X VBA)

    Hello, I need to generate a report for a document that tells the user if there are any nested tables (the intent is to let the user know that saving as Word 97 is not recommended at this point).

    I hoped to do this with a very simple For...Each loop. But I think I'm missing something obvious. A For...Each loop going through the Tables collection does not pick up the nested tables, as evident by my final test MsgBox:

    <pre>Public Sub test()
    Dim tbl As Table
    Dim rw As Row
    Dim cel As Cell
    Dim intTableCount As Integer

    intTableCount = 0
    For Each tbl In ActiveDocument.Tables
    intTableCount = intTableCount + 1
    If tbl.NestingLevel > 1 Then
    tbl.Shading.BackgroundPatternColorIndex = wdBlue
    MsgBox "Found table"
    End If
    For Each rw In tbl.Rows

    For Each cel In rw.Cells
    If cel.NestingLevel > 1 Then
    cel.Shading.BackgroundPatternColor = wdColorBlue
    End If
    Next cel
    Next rw
    Next tbl
    MsgBox "There are " & CStr(intTableCount) & " tables here."
    End Sub

    </pre>




    Is there another way to find these nested tables programatically?

    Kevin Elmore

    PS, I know that this code is not very efficient. I threw together some concepts in an attempt to detect the nested tables. Hopefully, I didn't make anyone go blind. *grin*

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Detecting Nested Tables (Word 200X VBA)

    Kevin, I haven't tried to work my way through your new code, but you could go back to my <post#=356700>post 356700</post#> in the thread on the Word board and do an accumulation rather than returning a true/false. (You would not have been notified of that post, since it wasn't in direct response to you, but I recommend always following up your threads because indirect replies happen quite frequently.)

  3. #3
    Star Lounger
    Join Date
    Apr 2003
    Location
    Kansas City, Missouri
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Detecting Nested Tables (Word 200X VBA)

    Thank you for that pointer. I cannot check back here all that often and rely on the system to send me e-mails when I get replies. I did not get that one. It would have saved me from creating this thread.

    And that thread will now be added to my Watched Threads, as well.

    Kevin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •