Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2006

Tip: Looking for answers? Try searching our database.

Copy Multiple Tables to Clipboard

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
C_P - 19 May 2006 18:44 GMT
I am currently working on a project where I would like to copy multiple
tables from one word document to another word document.  The problem
appears when in trying to copy multiple tables to the clipboard - I am
unsure of how to do this.  Using the DataObject, I can copy text (from
what I can understand), but I need to keep the actual format of the
table.

I am able to copy one table from the first document to the next, but
when I try to switch back to the first (using
ActiveWindow.Next.Activate or ActiveWindow.Previous.Activate), it will
not switch back.  Therefore, I would like to copy all the tables into
the clipboard (if possible).

Please advise.
Dave Lett - 19 May 2006 19:31 GMT
Hi C_P,

I would argue against switching back and forth between documents. Instead, I
think you can accomplish your goals by setting document objects and ranges
and using those to copy your tables from one document to the next. Have a
look at the following sample:

''' document containing the tables
Dim oDocTbl As Document
''' documet to copy tables to
Dim oDocInsert As Document
Dim lTbl As Long
Dim oRngTbl As Range
Dim oRngInsert As Range

'''these documents must be open
'''Set oDocTbl = Documents("DocTables.doc")
'''Set oDocInsert = Document("DocInsert.doc")

'''if they aren't open, then use something like the following
Set oDocTbl = Documents.Open(FileName:="C:\DocTables.doc")
Set oDocInsert = Documents.Open(FileName:="C:\DocInsert.doc")

'''cycle through the tables that you want to copy
For lTbl = 1 To oDocTbl.Tables.Count
   Set oRngTbl = oDocTbl.Tables(lTbl).Range
   Set oRngInsert = oDocInsert.Range
   With oRngInsert
       .Collapse Direction:=wdCollapseEnd
       '''insert the tables into the other document
       '''they will be inserted at the end for this
       '''demonstration
       .FormattedText = oRngTbl.FormattedText
       .Collapse Direction:=wdCollapseEnd
       .InsertAfter vbCrLf
       .Select
   End With
Next lTbl

'''close and save each document
oDocTbl.Close SaveChanges:=wdSaveChanges
oDocInsert.Close SaveChanges:=wdSaveChanges

Set oDocTbl = Nothing
Set oDocInsert = Nothing

HTH,
Dave
>I am currently working on a project where I would like to copy multiple
> tables from one word document to another word document.  The problem
[quoted text clipped - 10 lines]
>
> Please advise.
C_P - 22 May 2006 18:42 GMT
Thank you, that helped!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.