Copy table from one Word Doc to another

Joined
Sep 3, 2008
Messages
19
Programming Experience
1-3
I have 2 Word docs, doc 1 and doc 2, and I would like to copy the table in doc 1 to doc 2. Doc 1 has two tables and I would like to copy the second table. How would I be able to do this. I've searched the Internet for the past hour but couldn't find any information regarding this topic. Please provide code.


Thanks.
 
The Word Document is, shall we say, the younger and more inferior design to the Excel object, in that it can be very complicated and confusing as to which objects mean what.

Sometimes an object is a List or a Paragraph or both, you never know. However, Tables are the one thing they did right, which makes formatting and grabbing them very straight forward.

Word.Document.Tables() -- like excel is a 1 based collection of all the tables in the document.

Look into these object hierarchies, and you'll probably find what you are looking for:
VB.NET:
      Word.Document.Tables(1).Select()
      Word.Document.Content.Copy()
      Word.Document.Content.Paste()
      Word.Document.Content.PasteAppendTable()
      Word.Document.Content.PasteAsNestedTable()
      Word.Application.Selection.Copy()

Between the content and selection objects you should be able to play around and test with which method will get you want you want.
 
Back
Top