Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Aug 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Tables (word 2000, word 97)

    In a document I have multiple tables, how do i know what table number it is ? i am inserting tables at runtime...

    Thanks,

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Tables (word 2000, word 97)

    Your question is rather vague. "How do I know what table number it is". What is it? The table containing the selection? The most recently created table? The table you like best?

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Tables (word 2000, word 97)

    If you are adding the table yourself then it is best to create a variable of type Table and set this to point to the newly added table, as in...

    Dim tblNew as Table
    set tblNew = ActiveDocument.Tables.Add (Range:=Selection.Range, NumRows:=3, NumColumns:=3)

    You can then use tblNew to make whatever changes you need to your table.

    StuartR

  4. #4
    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: Tables (word 2000, word 97)

    Often you can use the .Count property. For example, to select the last table in the document body:

    ActiveDocument.Content.Tables(ActiveDocument.Conte nt.Tables.Count).Select

    To figure out which of the tables in the current "story" the cursor is in, you can create a range from the current selection back to the beginning of the document and then count the tables in that range:

    Sub TableNumIs()
    MsgBox InTableNumber
    End Sub

    Function InTableNumber() As Integer
    ' Check to confirm the selection is within a single table
    If Not Selection.Information(wdWithInTable) Then
    InTableNumber = 0
    Exit Function
    End If
    ' Set a range from the end of the current table to top of doc
    Dim rngTemp As Range
    Set rngTemp = Selection.Tables(Selection.Tables.Count).Range
    rngTemp.Start = 1
    ' Set return value and clean up objects
    InTableNumber = rngTemp.Tables.Count
    Set rngTemp = Nothing
    End Function

Posting Permissions

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