Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 07-05-2012, 12:08 PM
Testor Testor is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Jul 2012
Posts: 2
Testor is on a distinguished road
Default How do you set rich text in a content control


Forgive me I'm lost and bewildered!
I have a document with several Plain Text Content Controls. So far, I can enumerate the SdtElements in the document , find all the SdtBlocks of interest and replace the text as needed ok.
Next though, I have one field in RichText format that I can retrieve from a database as a string and now need to insert this into the document. I've set up a Rich Text Content Control in the document but how do I set/replace this with the rich text string and retain the proper formatting?
Just to make me more confused, when I open the document with the "Word 2007 Content Control Toolkit" it shows all the Content Controls as expected and properly identifies the one as Rich Text type. When, however, I open the document using the "Open XML SDK 2.0 Productivity Tool" it shows the rich text control as a plain simple SdtBlock that appears completely indistinguishable from the plain text content controls and the reflected code seems identical?
How then to set the RichText string in the document?
Reply With Quote
  #2  
Old 07-05-2012, 01:31 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,296
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Hi Testor,

With a Rich Text Content Control, you can paste formatted text into it, or format its content after populating it.

As for identifying the type, there seems to be a bug in the data returned - the same happens with vba.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 07-05-2012, 04:18 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,296
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Actually, the bug seems transient. I've just re-tested with vba and am getting the correct values. Maybe re-starting Word or rebooting your system will fix the issue.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #4  
Old 07-07-2012, 10:24 AM
Testor Testor is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Jul 2012
Posts: 2
Testor is on a distinguished road
Default

Thanks for the reply but it doesn't really answer the question.

I'm sure a Word user can paste rich text into a document (content control or not!). My problem, though, is I have a rich text string I need to embed in a document on a back end service using nothing more than .NET's DocumentFormat.OpenXml assembly and I still don't have a clue how to do that.

Any guidance would be greately appreciated.
Reply With Quote
  #5  
Old 07-08-2012, 07:55 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,296
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

I haven't worked with OpenXml, so I can't advise directly. However, if you save two copies of a document, one with an empty Rich Text CC and one with the same CC filled, the resulting XML code should give you an idea of what's required.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rich text/Plain text Content Controls in Template michael.fisher5 Word 9 11-19-2014 06:36 AM
Word2010 check boxes and plain text content control boxes in same table fcsungard Word 5 06-01-2012 01:16 AM
Content control titles jillapass Word VBA 3 05-29-2012 06:11 AM
Rich Text Content Control - Allow User Formatting keithacochrane Word 1 05-28-2012 05:06 PM
Templates: automatic text generation from Rich Text content control Chickenmunga Word 0 10-01-2008 11:16 AM


All times are GMT -7. The time now is 03:24 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft