Word table copy

M

miga

Hi,

I'm trying to copy a table - identified by a bookmark on a formfield
within the table - to another position in the document. More
specifically, the insert location is just after another table which
also can be identified only by the bookmark of a formfield within the
destination table. I guess my problem is identifying the destination
insert point of the new table which ideally should be the first
paragrap after the destination table - but how ?

Copying the table goes as follows:

If (Selection.BookmarkID <> Empty) Then
ActiveDocument.Unprotect (DocPassword)
Selection.Tables(1).Range.Copy
.....

Which works as intended. Pasting the table, however, does not insert
it in the correct spot. I've tried:

Selection.Paragraphs(1).Range.PasteSpecial

trying to insert it into the first paragraph after the table. This
inserts the source table into the current - selected - formfield in
the table.

Any help is highly appreciated.

Best regards and thanks,

Michael
 
G

Graham Mayor

If you want the table reproducing immediately after that table then
following on from your table numbering

With ActiveDocument.Tables(1).Range
.Copy
.Select
End With
With Selection
.MoveDown
'.TypeParagraph 'if you want a blank line between the tables
.Paste
End With

should work

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

miga

If you want the table reproducing immediately after that table then
following on from your table numbering

With ActiveDocument.Tables(1).Range
    .Copy
    .Select
End With
With Selection
    .MoveDown
   '.TypeParagraph 'if you want a blank line between the tables
    .Paste
End With

should work

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>














- Show quoted text -

Hi Graham,

Thanks for yor prompt response. I did figure it out by inserting a
range after the table, adding a paragraph and inserting the table
after the paragraph.
I have another problem though: I can locate a formfield within a table
using
"ActiveDocument.FormFields(Selection.BookmarkID)"
and the corresponding table, the formfield is embedded in, using:
"Selection.Tables(1)"

But how can I iterate over all formfields within the table ?
I have tried "Selection.FormFields(Ix)" but this is always empty. My
problem is that first I need to copy a table containing formfields,
and secondly, I need to change the bookmark names of the formfields in
the destination table.
(since they are copied, they will be set to null by Word as they have
the same name). The (bookmark) names of the formfields in the
destination table are modified slightly based on the source formfield
(bookmark) names.

Best regards and thanks,

Michael
 
G

Graham Mayor

I did something similar for another user a while back - the results can be
found on my web page http://www.gmayor.com/word_vba_examples.htm. - Add a
row to a table in a protected form

This adds the rows one at a time, and may give you enough of a spur to work
out what you need for your situation.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

miga

I did something similar for another user a while back - the results can be
found on my web pagehttp://www.gmayor.com/word_vba_examples.htm.  - Adda
row to a table in a protected form

This adds the rows one at a time, and may give you enough of a spur to work
out what you need for your situation.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>










- Show quoted text -

Helo again,

You've got a lot of good stuff in there - great !

I also did figure the other problem out
(Selection.Tables(1).Range.Formfields(Ix) ), so now there's only one
remaining: how to get a range on the inserted/copied table ?
I.e. after invoking Range.PasteSpecial, how do you get a handle/id/
range on the inserted table ?

Best regards and thanks,

Michael
 

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