View Single Post
 
Old 08-13-2021, 08:51 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Provided the two tables are the same size then


Code:
Sub Macro1()
'Graham Mayor - https://www.gmayor.com - Last updated - 14 Aug 2021
Dim oSource As Document, oTarget As Document
Dim oTable1 As Table, oTable2 As Table
Dim oRng1 As Range, oRng2 As Range
Dim i As Long
    Set oTarget = Documents.Add("C:\Path\Doc A.docx")
    Set oSource = Documents.Open("C:\Path\Doc B.docx")
    Set oTable1 = oSource.Tables(1)
    Set oTable2 = oTarget.Tables(1)
    For i = 4 To oTable1.Rows.Count
        Set oRng1 = oTable1.Cell(i, 3).Range
        oRng1.End = oRng1.End - 1
        Set oRng2 = oTable2.Cell(i, 3).Range
        oRng2.End = oRng2.End - 1
        oRng2.FormattedText = oRng1.FormattedText
        If oRng2.Text = "" Then
            oRng2.Text = "###"
            oRng2.Font.Name = "Times New Roman"
            oRng2.Font.Size = 22
        End If
    Next i
lbl_exit:
    oSource.Close 0
    Set oTarget = Nothing
    Set oSource = Nothing
    Set oTable1 = Nothing
    Set oTable2 = Nothing
    Set oRng1 = Nothing
    Set oRng2 = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com

Last edited by gmayor; 08-14-2021 at 08:43 PM.
Reply With Quote