gmaxey
08-02-2015, 03:26 PM
Today I have fallen off the turnip truck. I can't seem to work anything out.
I have 2 X 3 parent table with a 1 x 2 nested table in cells 1, 2 and 3. I can select, cut and paste the nested table in cell 3 into cell 4 using the mouse, but nothing I've tried with VBA works. I either end up with the table pasted BETWEEN rows 1 and 2. Or I just get the text of the nested table (no cells, borders, etc.) in cell 4.
Sub CutAndPasteNestedTable()
Dim oTblParent As Table
Dim oTblToCut As Table
Dim oRng As Range
'I have a simple 2 X 3 table with a sime 1 X 2 nested table in cell 3.
'I want to cut the nested table from cell 3 and paste it in cell 4.
Set oTblParent = ActiveDocument.Tables(1)
Set oRng = oTblParent.Range.Cells(3).Range
oRng.End = oRng.End - 2
'I 've got then nested table.
Set oTblToCut = oRng.Tables(1)
oTblToCut.Range.Cut
'The table is now in the clipboard. If I end, I can select the start of
'cell 4 and paste the table cut from cell 3.
'End
'However, if I try to do that programatically, the table cut is pasted in between the table rows 1 and 2
Set oRng = oTblParent.Range.Cells(4).Range
oRng.Collapse wdCollapseStart
oRng.Paste
End Sub
I have 2 X 3 parent table with a 1 x 2 nested table in cells 1, 2 and 3. I can select, cut and paste the nested table in cell 3 into cell 4 using the mouse, but nothing I've tried with VBA works. I either end up with the table pasted BETWEEN rows 1 and 2. Or I just get the text of the nested table (no cells, borders, etc.) in cell 4.
Sub CutAndPasteNestedTable()
Dim oTblParent As Table
Dim oTblToCut As Table
Dim oRng As Range
'I have a simple 2 X 3 table with a sime 1 X 2 nested table in cell 3.
'I want to cut the nested table from cell 3 and paste it in cell 4.
Set oTblParent = ActiveDocument.Tables(1)
Set oRng = oTblParent.Range.Cells(3).Range
oRng.End = oRng.End - 2
'I 've got then nested table.
Set oTblToCut = oRng.Tables(1)
oTblToCut.Range.Cut
'The table is now in the clipboard. If I end, I can select the start of
'cell 4 and paste the table cut from cell 3.
'End
'However, if I try to do that programatically, the table cut is pasted in between the table rows 1 and 2
Set oRng = oTblParent.Range.Cells(4).Range
oRng.Collapse wdCollapseStart
oRng.Paste
End Sub