A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

A function which returns the "index" of a table



 
 
Thread Tools Display Modes
  #1  
Old March 10th, 2010, 11:11 AM posted to microsoft.public.word.tables
TimvG
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
Ads
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:26 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright 2004-2018 OfficeFrustration.
The comments are property of their posters.