PDA

View Full Version : Getting a reference to a word table



mark007
06-06-2005, 04:37 AM
I have a macro that pastes a table into word at the current location of the cursor i.e. it uses selection.paste.

When I have pasted this table in I need to get a reference to it i.e.

set t=wddoc.tables(x)

How can I determine the x? Or alternatively how else could I get a reference to this table?

Thanks.


:)

Killian
06-06-2005, 05:33 AM
Hi Mark,
if you set a range to the selection first and paste your table into that range, your range will then contain your table... if you see what I meanSet rngTemp = Selection.Range
rngTemp.Paste
'rngtemp is now your table

mark007
06-06-2005, 05:34 AM
So I could then get the table using:

set t=rngTemp.Tables(1)

I assume?

:)

Killian
06-06-2005, 05:36 AM
yup

fumei
06-06-2005, 08:31 AM
OR; if you want, you could, just before you paste the table, pick up the current table count, then you be able to know the index number. This works, of course, as long as you dio not insert a table PRIOR to this one, AFTERWARDS.

Dim oTable As Table
Dim i As Integer

i = ActiveDocument.Tables.Count + 1
Selection.Paste ...blah blah
set oTable = Activedocument.Table(i)

Now you have a explicit reference to that table, as a Table object, with all the appropriate properties and methods of a Table object, rather than a Range object. There are advantages/disadvantages for either way.

fumei
06-08-2005, 07:08 AM
I am an idiot....just realized that you ARE set the reference as a Table object. Doh!

TonyJollans
06-08-2005, 09:35 AM
You don't need to use a Range as well as the Selection - of course a Range is better but if you're working with the Selection anyway you can do ..

Selection.Paste
Set tbl = Selection.Tables(1)

mark007
06-09-2005, 12:54 PM
Ok, will try it out.

Cheers!

:)