Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2005

Tip: Looking for answers? Try searching our database.

Copying formatted text from one cell in a table to another cell in another table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nick Russell - 24 Jan 2005 15:26 GMT
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/
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.