Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
TimvG TimvG is offline
external usenet poster
 
Posts: 12
Default A function which returns the "index" of a table

A few years back somebody asked how one would find out the "index" of
a nested table. By this they meant that if you a bunch of tables
nested inside another table (all at the same nesting level), how do
you find out whether your currently selected table is the first, the
second, the third, or... It seems that they didn't get the answer
they needed and the matter was dropped.

As it happens I met this same problem today. Here's a solution:

Function TableNumber()

Dim TempRange As Range
Dim TableIndex As Integer
Dim aTable As Table

If Selection.Information(wdWithInTable) And
Selection.Tables(1).NestingLevel 1 Then
Let Selection.Tables(1).ID = "Fred"
Set TempRange = Selection.Range
Do While Selection.Tables(1).NestingLevel =
TempRange.Tables(1).NestingLevel
Selection.MoveDown
Loop
Let TableIndex = 0
For Each aTable In Selection.Cells(1).Tables
TableIndex = TableIndex + 1
If aTable.ID = "Fred" Then
TableNumber = TableIndex
Exit For
End If
Next
TempRange.Select
Let Selection.Tables(1).ID = ""
MsgBox TableNumber
End If
End Function
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Do not want to display "Table IV." in Index of Tables/Figures Emily Microsoft Word Help 1 June 24th 09 01:19 PM
Styles "cross" or "bridge" para returns WilliamWMeyer Formatting Long Documents 2 April 23rd 08 06:15 PM
Setting up an index directory in a Word doc does NOT work / "No index entries found" Goran Ivanic Microsoft Word Help 1 October 27th 06 04:48 PM
The search "Find Next" with "wildcards" does not function properly Philos Microsoft Word Help 4 September 10th 06 06:43 AM
How to override Words built-in "Draw a table"-function Mo Tables 2 November 10th 05 02:25 PM


All times are GMT +1. The time now is 01:39 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"