Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Thanked 0 Times in 0 Posts

    Determine which table... MSWord 2003

    Hi all,
    I have a document with a variable number of tables in it. There is a piece of text that always appears, and is always contained within row 1, cell2 of either table 1 or table 2.

    How would I determine in a VBA function which table the text appears in?

    Any advice would be gratefully received.



  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 93 Times in 89 Posts
    This approach is a bit of a blunt instrument, but it might work for your purposes. It creates a range from the end of the Selection to the beginning of the content and then reports the number of tables in the range, on the theory that the selection must be in the last table.

    Sub SelectionIsInTableNumber()
    If Selection.Information(wdWithInTable) Then
        Dim rngTemp As Word.Range
        Set rngTemp = ActiveDocument.Range(ActiveDocument.Content.Start, Selection.End)
        MsgBox rngTemp.Tables.Count, vbInformation + vbOKOnly
        Set rngTemp = Nothing
        MsgBox "Not in a table", vbExclamation + vbOKOnly
    End If
    Edit: It occurs to me that this might not work in headers, footers, and other panes outside the main body...
    Last edited by jscher2000; 2011-10-10 at 13:47. Reason: Hmmm...

Posting Permissions

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