View Single Post
 
Old 10-30-2020, 01:14 PM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Code:
Sub CopyTables() Dim oDoc As Document Dim oDocTarget As Document Dim oTbl As Table, oTblTarget As Table Dim oRng As Range   Set oDoc = ActiveDocument   Set oDocTarget = Documents.Add   For Each oTbl In oDoc.Tables     Set oRng = oDocTarget.Range     With oRng       .Collapse wdCollapseEnd       oRng.FormattedText = oTbl.Range.FormattedText       Set oTblT = oRng.Tables(1)       oTblT.Style = "Table Grid"       .Collapse wdCollapseEnd       .Text = vbCrLf     End With   Next
   'It is called stet:   'oDocTarget.Range.Select   'Selection.ClearFormatting   'Selection.Collapse wdCollapseStart   oDoc.Activate lbl_Exit:   Exit Sub End Sub
[moderator attempt to reformat - think I got it right - CK ]



Code:
Sub CopyTables()
   Dim oDoc As Document
   Dim oDocTarget As Document 
   Dim oTbl As Table, oTblTarget As Table 
   Dim oRng As Range   
   Set oDoc = ActiveDocument   
   Set oDocTarget = Documents.Add   
   For Each oTbl In oDoc.Tables     
      Set oRng = oDocTarget.Range     
      With oRng
        .Collapse wdCollapseEnd
        .FormattedText = oTbl.Range.FormattedText
         Set oTblT = oRng.Tables(1)
         oTblT.Style = "Table Grid"
        .Collapse wdCollapseEnd
        .Text = vbCrLf
     End With
   Next
   'It is called 
stet:
   'oDocTarget.Range.Select
   'Selection.ClearFormatting
   'Selection.Collapse wdCollapseStart
   oDoc.Activate
lbl_Exit:
   Exit Sub 
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/

Last edited by Charles Kenyon; 11-02-2020 at 04:39 PM.
Reply With Quote