IDENTIFY TABLES IN THE DOC

A

Alok

Hi all
Could you plz tell me if there is some information( may be hidden )
associated to the table inserted in the doc.
I am using VBA to access the tables from the doc. but cannot make the
identity of those tables.

Thanks,
Alok
 
H

Helmut Weber

Hi,
tables have indices, like
activedocument.tables(4).select.

Which table is the start of the selection in?

Dim r As Range
Selection.Tables(1).Select
Selection.Cells(2).Select
Set r = Selection.Range
r.Start = 0
MsgBox r.Tables.Count

I am selecting the second (!) cell in the table,
as with cell(1) I get some strange results.

If the cursor (insertion point) was at the start
of cell(1) I get:

MsgBox r.Tables.Count = 0 on first run, and
MsgBox r.Tables.Count = 1 on second run

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
F

fumei

You would get an error if the current Selection is NOT in a table. You
should always use a Selection.Information (wdWithinTable) to check.

I can not see the intention of setting r.Start = 0. Start is a Long
Integer, and 0 = the start of the document - not the start of a cell or table
or anything else. Could you please explain?
 
H

Helmut Weber

Hi fumei,
of course, you would get an error.
Advices here are not ready to use solutions.
There are always preconditions.
I can not see the intention of setting r.Start = 0. Start is a Long
Integer, and 0 = the start of the document - not the start of a cell or table
or anything else. Could you please explain?
???

How else would you like to find out,
what table the beginning of the selection is in?

Long or integer doesn't matter.

Or I am missing not only the point, but all?

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
A

Alok

Ya Helmut
Thanks for that .
But this creates abmbiguity when the one table is deleted (accidently ..).
eg. The Tables(4) will become Tables(3) now .

Can we identify the table's uniqueness somehow ?

which does not alter the numbers i m using .
or is applying the hard code logic the only way?

Thanks,
Alok
 
H

Helmut Weber

Hi,
I don't think there is a clean simple way,
covering all possibilities, such as merging tables,
splitting tables, deleting tables, adding tables.
Not to speak of nested tables.

Unless you store all information about the tables
at a given point in time e.g. in a logfile,
and check afterwards, whether anything has changed.

However, within one single macro, or on a larger
scale in a (modeless) userform, you may first
assign each table to a table object and get an
error 5825, object deleted, in case it's gone.

Like this:

Sub test301()
Dim oTbl() As Table ' table object
Dim iTbl As Integer ' counter
ReDim oTbl(ActiveDocument.Tables.Count)
For iTbl = 1 To ActiveDocument.Tables.Count
Set oTbl(iTbl) = ActiveDocument.Tables(iTbl)
Next
oTbl(4).Select
Selection.Cut
oTbl(4).Select ' error 5825
End Sub

I think, you can take care of
an error handler yourself, otherwise
ask again.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top