#1
|
|||
|
|||
Moving formatted text from one table to another
I have an issue moving formatted text from a cell in one table to another. If I just set the text property, everything works fine, but trying to get the text to keep the current formatting is proving much more work than necessary.
My initial testing just set the text property so: Code:
destTable.Cell(1,1).range.text = SourceTable.Cell(1,1).range.text Code:
destTable.Cell(1,1).range.formattedText = SourceTable.Cell(1,1).range.formattedText All I want to do is set the contents of one cell to another, and maintain the same formatting. Why does this seem to be impossible!? |
#2
|
|||
|
|||
I am having better results using
Code:
SourceTable.Cell(1,1).range.copy destTable.Cell(1,1).range.pasteandformat (wdFormatOriginalFormatting) |
#3
|
||||
|
||||
What you need to do is to transfer the paragraph format attached to the end-of-cell marker, along with the rest of the cell contents. For example:
Code:
Sub Demo() Dim Tbl1 As Table, Tbl2 As Table Dim Rng1 As Range, Rng2 As Range Dim i As Long With ActiveDocument Set Tbl1 = .Tables(1) Set Tbl2 = .Tables(2) For i = 1 To Tbl1.Range.Cells.Count Tbl2.Range.Cells(i).Range.Paragraphs.Last.Range.ParagraphFormat = _ Tbl1.Range.Cells(i).Range.Paragraphs.Last.Range.ParagraphFormat Set Rng1 = Tbl1.Range.Cells(i).Range With Rng1 .End = .End - 1 End With Set Rng2 = Tbl2.Range.Cells(i).Range With Rng2 .End = .End - 1 .FormattedText = Rng1.FormattedText End With Next End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
Thanks again for your continued assistance, this is exactly what I needed!
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
AutoCorrect with Formatted Text | pmokover | Word | 15 | 05-11-2017 08:50 PM |
Inserted AutoText table incorrectly formatted - unless macro paused! | Smallweed | Word VBA | 4 | 01-16-2014 03:15 PM |
Text auto formatted as date format | Aikeedoh | Excel | 5 | 09-06-2013 02:38 AM |
Import formatted text from Word into PowerPoint | parboy | PowerPoint | 0 | 07-06-2011 08:52 AM |
Insert formatted table into word (mail merge) | manojbmsce | Mail Merge | 0 | 09-25-2008 02:25 AM |