Dear All,
I'm trying to copy some text from a cell in one table, to a cell in another table above the current text, while preserving the formatting. I don't want to use the clipboard as I don't want to disturb it.
Anyway, the code I have right now is as follows:
Dim OriginalText As Range
Dim InsertText As Range
To get the formatted text from a cell I'm using this code:
Set OriginalText = SourceTable.Cell(RowNum, ColNum).Range
To insert the formatted text I'm using this code:
Set InsertText = DestinationTable.Cell(RowNum, ColNum).Range
With InsertText
.Collapse Direction:=wdCollapseStart
.FormattedText = OriginalText.FormattedText
End With
Instead of inserting the formatted text in the cell before the current text, it simply blanks out the whole row!!! Very bizzare! If I write the formatted text to, say, the beginning of the Active Document, it comes out fine (albeit with an unprintable character following though).
Does anyone have any ideas where I'm going wrong, or what I need to be doing instead?
Cheers,
Nick
Helmut Weber - 24 Jan 2005 16:27 GMT
Hi Nick,
according to my experience,
ranges and tables don't go together well.
However, this seems to work:
Dim r1 As Range ' cell in table 1
Dim r2 As Range ' cell in table 2
With ActiveDocument
Set r1 = .Tables(1).Cell(1, 1).Range.FormattedText
r1.End = r1.End - 1 ' seems to be crucial: 1 not 2!
Set r2 = .Tables(2).Cell(1, 1).Range.FormattedText
r2.End = r2.End - 1
r2.FormattedText = r1.FormattedText
End With
Forgive me for saying so,
your code seems odd altogether,
so to me, there is no way of pointing out
what is wrong in detail.
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/