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 / March 2005

Tip: Looking for answers? Try searching our database.

Append formatted text to a table cell

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew Bernhardt - 18 Mar 2005 05:32 GMT
How do I append formatted text to a table cell that has text with a
different format (i.e. append a word in blue letters to a cell that has
words in other colors)? If I set a range to a cell and collapse it to the
end of the range, the text will get added to the next cell.

For example, if a document has one table and I want to append the word
"TEST" in red letters to cell(1,3), the following does not work:

 Dim R As Range
 Set R = ThisDocument.Tables(1).Cell(1, 3).Range
 R.Collapse wdCollapseEnd
 R.InsertAfter "TEST"
 R.Font.Color = wdColorRed

The word is instead added to the beginning of cell(1,4).

- Andrew Bernhardt
Jean-Guy Marcil - 18 Mar 2005 06:21 GMT
Andrew Bernhardt was telling us:
Andrew Bernhardt nous racontait que :

> How do I append formatted text to a table cell that has text with a
> different format (i.e. append a word in blue letters to a cell that
[quoted text clipped - 11 lines]
>
> The word is instead added to the beginning of cell(1,4).

This is because the cell range includes the end of cell marker (?). So, when
you collapse, the range starts *after* the cell marker in cell 1,3, i.e at
the beginning of cell 1,4.

Try this instead:

'_______________________________________
Dim R As Range

Set R = ActiveDocument.Tables(1).Cell(1, 3).Range
With R
   .MoveEnd wdCharacter, -1
   .Collapse wdCollapseEnd
   .InsertAfter "TEST"
   .Font.Color = wdColorRed
End With
'_______________________________________

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

andyb@volcanomail.com - 31 Mar 2005 19:39 GMT
Thanks, that is what I was looking for.

- Andrew

> Andrew Bernhardt was telling us:
> Andrew Bernhardt nous racontait que :
[quoted text clipped - 16 lines]
>
> This is because the cell range includes the end of cell marker (¤).
So, when
> you collapse, the range starts *after* the cell marker in cell 1,3, i.e at
> the beginning of cell 1,4.
[quoted text clipped - 19 lines]
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org

Rate this thread:






 
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.