![]() |
|
|
|
#1
|
||||
|
||||
|
Try the following macro. Add it to your destination document (or to Word's 'Normal' template and activate your destination document), then run it. Select the source document and the destination document will be updated.
Note: I had to change your source row references, plus some destination column references, and you seemed to have too many cells overall. I've also managed to exclude the source table headings. Code:
Sub XferTblData()
Application.ScreenUpdating = False
Dim DocSrc As Document, TblSrc As Table, RngSrc As Range, RowSrc As String, ColSrc As String
Dim DocTgt As Document, TblTgt As Table, RngTgt As Range, RowTgt As String, ColTgt As String
Dim i As Long
RowSrc = "5,5,6,6,7,7,9,9,11,11"
ColSrc = "1,2,1,2,1,2,1,2,1,2"
RowTgt = "10,10,12,12,14,14,17,17,20,20"
ColTgt = "1,2,1,2,1,2,1,2,2,3"
Set DocTgt = ActiveDocument
With Application.Dialogs(wdDialogFileOpen)
If .Show = -1 Then
.AddToMru = False
.ReadOnly = True
.Visible = False
.Update
Set DocSrc = ActiveDocument
End If
End With
If DocSrc Is Nothing Then Exit Sub
Set TblSrc = DocSrc.Tables(2)
Set TblTgt = DocTgt.Tables(1)
For i = 0 To UBound(Split(RowSrc, ","))
Set RngSrc = TblSrc.Cell(Split(RowSrc, ",")(i), Split(ColSrc, ",")(i)).Range
RngSrc.End = RngSrc.End - 1
RngSrc.Start = RngSrc.Paragraphs(1).Range.End
Set RngTgt = TblTgt.Cell(Split(RowTgt, ",")(i), Split(ColTgt, ",")(i)).Range
RngTgt.End = RngTgt.End - 1
RngTgt.FormattedText = RngSrc.FormattedText
Next
DocSrc.Close SaveChanges:=False
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#2
|
|||
|
|||
|
This is AMAZING, Paul! Thank you! I do get the below message. I click and END and it completes the macro. Row 10, Col 2 of the target doc doesn't get populated with content (Row 20, Col 2 of the source).
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Copy content control entries to next table next page | Mel_Herndon | Word VBA | 2 | 05-22-2014 05:07 PM |
Deleting a table from a content control -- preserving the content control
|
BrainSlugs83 | Word Tables | 8 | 11-14-2013 03:06 AM |
Content of all documents in folder changes to match one of them
|
jemmac2525 | Word | 2 | 11-11-2013 12:32 AM |
| table of content | suna | Word | 2 | 05-16-2013 02:39 PM |
share content between documents?
|
albytrott | Word | 1 | 10-08-2009 08:27 AM |