Word.Tips.Net WordTips (Menu Interface)

Index Number for the Active Table

Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Index Number for the Active Table.

Mary is writing a macro that will split a table. Working on the active table isn't much of a problem, but she wants to copy the first row of the active table, then split the table, and finally paste the copied row to the first row of the new table created by the split. In order to do this properly, she wants to determine the index numbers used by Word to reference the two tables in the Tables collection. Mary wants to know how she can discover the index number for the active table (before the split) so she can simply increment that number to know the new index number for the table created after the split.

Word's object model relies on organizing individual objects into collections that can be accessed programmatically. This goes not only for tables, but for paragraphs, graphics, and a host of other objects. You can easily find the number of objects in a collection using the Count property. For instance, you could use the following to discover how many tables are in a document, as it returns the number of objects in the Tables collection:

iNumTables = ActiveDocument.Tables.Count

Finding which table is the current one is a bit trickier, but it can be done. The simplest way is to add a bookmark to the current table, and then examine all the tables in the document to see which table contains that bookmark. Once you find that out, you know which table is the current one, and you can delete the bookmark. The following macro implements these steps:

Sub FindTableNumber()
    Dim J As Integer
    Dim iTableNum As Integer
    Dim oTbl As Table

    Selection.Bookmarks.Add ("TempBM")
    For J = 1 To ActiveDocument.Tables.Count
        Set oTbl = ActiveDocument.Tables(J)
        If Selection.Bookmarks.Exists("TempBM") Then
            iTableNum = J
            Exit For
        End If
    Next J
    MsgBox "The current table is table " & iTableNum
End Sub

To use the macro, simply make sure that the insertion point is within the desired table. The macro can be easily adapted to a larger context, such as one where the table is split and otherwise manipulated.

There is another way to programmatically handle the underlying action that Mary wants to achieve, however—a method that doesn't require the use of index numbers for the Tables collection. You could copy the first row of the table and then split the table using a command similar to the following:


This command splits the table at row 5; you can easily change the splitting point by changing the row at which it is split. Then, you can move the insertion point to the beginning of the next table (the newly created one) by using the following command:

Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext

This command jumps to the beginning of the next table, and you can then paste the header row you copied earlier.

If you are interested in a more detailed discussion on how to programmatically handle tables, you can find an excellent article here:


WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (505) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Index Number for the Active Table.

Related Tips:

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!


Leave your own comment:

  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*What is 5+3 (To prevent automated submissions and spam.)
           Commenting Terms

Comments for this tip:

Hire    21 Jan 2016, 19:10
in my project, I have a big data on word documents including lots of merged or non merged tables on different pages. my requirement is that i have to split all the rows of each tables with in the word documents.

Please help its urgent.

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us


Advertise with Us

Our Privacy Policy

Our Sites


Beauty and Style




DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)



Home Improvement

Money and Finances


Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives


Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2016 Sharon Parq Associates, Inc.