PDA

View Full Version : Word tables copy and paste



dksj
08-02-2007, 03:02 PM
I need to copy a standard table into Word documents created using a template. I have figured out how to sort through and open word file objects in a directory but dont know the syntax for copying a table from one Word file to another. The objective is to go out to a library directory go through each folder, open up all word files and paste a table into the document. There are already 7 tables in the template and the new one to be pasted should be located after the 5th table. The actual Macro procedure will be launched from an Excel tool. Thanks,

dksj

fionabolt
08-03-2007, 12:48 AM
DKSJ

Rather than using copy and paste. I think I would use AutoText.

So in your Word template, create the table. Select it. Click Insert, Autotext, Autotext, use the drop down for "Look in" to select the template you are working on (DO NOT USE ALL ACTIVE TEMPLATES), give the AutoText entry an appropriate name and click OK.

Now in your code you can put something like this (you would need to amend this to run from Excel, this is the syntax for Word):
Documents("docname").AttachedTemplate.AutoTextEntries("autotextname"). _
Insert where:=Selection.Range, RichText:=True


Of couse selection.range could be replaced in your code with some other range, you don't actually have to select it.

Does that help?

Regards,
Fiona

fumei
08-06-2007, 03:44 AM
There are already 7 tables in the template and the new one to be pasted should be located after the 5th table. THAT has to be clarified better. Is there text between the existing Table 5 and Table 6? The new table will be table 6, but what is between it and the previous one?

Autotext would work. However, there was an assumption there that the existing documents have the same attached template. Maybe they do, maybe they don't. It certainly would make a difference.

Where is the table coming from? You mention Excel, yet you also say "copying a table from one Word file to another".

If AutoText is not strictly viable, the best way would be to simply make a table object - from where ever - and use it.

BTW: "There are already 7 tables in the template and the new one to be pasted should be located after the 5th table." I assume "template" there is a actually meant to be "document".

BTW: using a table object is easy.