Adding a table to a range object

M

Marco Boeijen

Hello,

I have the following problem.

I made a template in Word containing bookmarks. From my Access VBA
code I can point to those bookmarks and add data there using a Range
object. So far so good.

Now I'm trying to copy tables at the end of my Range object using a
For Next loop. The tables are based on the first table that's already
there. Here's my problem. When in the same loop I try to put data in
the table It's using the first table instead of the newly added table.
It seems like the tables are added after the Range object instead of
before the end of the Range opbject.

Here's my code:

Set oRange = oDoc.Bookmarks(strBookMarkName).Range
oDoc.Range.Tables(1).Range.Copy

For intCounter = 1 To 10
oRange.Paste
oRange.Tables(intCounter).Rows(1).Cells(2).Range.InsertAfter
"Text"

Next intCounter

When intCounter reaches 2 it gives an error message saying the
requested member of the collection does not exist. If I ask for
oRange.Tables.Count it says 1 and not 2. So the newly added table
isn't part of the Range object.

Can anyone help me out here?


Kind regards,

Marco Boeijen
 
H

Helmut Weber

Hi Marco,
without understanding your question completely,
it seems to me that a "new" table is melted with
an existing table, if inserted immediately after.
Think , you have to insert a seperator before.
A simple chr$(13) would be sufficient.
You enlarge tables(1) instead of creating a new one.
AFAIK.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
 

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