View Single Post
 
Old 03-16-2017, 06:09 AM
Fredrik1987 Fredrik1987 is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Mar 2017
Posts: 3
Fredrik1987 is on a distinguished road
Default

I'll try to explain better, Sorry if I'm wasting to much of your time.
My question is: If a table has only 1 row, are there any problems/limitations with the Range.paste method I'm not aware of?


Added a crude code below, hope it explains to some extent what I'm trying to achieve.


Code:
'/  Copy tables from master document to userdoc
Sub CopyTables( _
)

Dim MasterDoc As Word.Document
Dim UserDoc As Word.Document
Dim MyTable As Word.Table
Dim rng_Paste As Variant

Dim MyCell As Word.Cell
Dim i As Integer


Set MasterDoc = Documents("MasterDoc.docx")
Set UserDoc = Documents("UserDoc.docm")


'/  Paste content from tables in MasterDoc to tables in UserDoc
For Each MyTable In MasterDoc.Tables
    i = i + 1
    For Each MyCell In MyTable.Columns(1).Cells
    
        
        Set rng_Paste = UserDoc.Tables(i).Cell(MyCell.RowIndex, 1).Range
        
        
        '/   If the number of rows = 1, it inserts a new column instead of replacing the 
        '/   content in rng_Paste. If number of rows > 1 it replaces the content of
        '/   rng_Paste (As it should)

        MyCell.Range.Copy
        rng_Paste.Paste wdFormatOriginalFormatting
    
    
    Next
Next


End Sub

Regarding the content; It's mainly text/hyperlinks, though it seems like the problems relates to the number of rows in a table, and not the content itself. It works just fine with any table if the number of rows is grater than

As for the if/else, there's two possibilites (As I see them):
  1. The UserTable doesn't contain the information, if so add a new row and copy from masterdocument
  2. The information exist, if so; Replace (Update) the content in UserTable with content from MasterTable
Reply With Quote