Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    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.

    Thanks,

    Violet

  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
    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.

    Code:
    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
    Else
        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 14: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
  •