Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

IDENTIFY TABLES IN THE DOC

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alok - 21 Dec 2004 11:04 GMT
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
Helmut Weber - 21 Dec 2004 13:08 GMT
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
fumei - 21 Dec 2004 16:56 GMT
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?
Helmut Weber - 21 Dec 2004 17:46 GMT
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/
Alok - 22 Dec 2004 05:32 GMT
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

> Hi,
> tables have indices, like
[quoted text clipped - 22 lines]
> "red.sys" & chr(64) & "t-online.de"
> Word 2002, Windows 2000
Helmut Weber - 22 Dec 2004 08:45 GMT
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
Alok - 23 Dec 2004 05:43 GMT
well i had that idea as a backup option.
thanks anyway

Thanks,
Alok

> Hi,
> I don't think there is a clean simple way,
[quoted text clipped - 33 lines]
> "red.sys" & chr(64) & "t-online.de"
> Word 2002, Windows 2000
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.