#1
|
|||
|
|||
Rich Text Content Controls: Formatting?
In the attached file,
I have made two Rich Text Content Control. I want the first one to be styled and I have already styled the Control. But when I fill in new texts in the first Control, the texts typed in are styled as expected. Please kindly take a look at the attached example. Thank you. Rich Text Content Controls - Formatting.docx |
#2
|
|||
|
|||
I have found a way to do so.
1. Select the Rich Text Content Control 2. Properties (Developer Tab - Controls) 3. Use a style to format contents However, how could I do this in VBA? Code:
Sub a() Dim oStyle As Style Set oStyle = ActiveDocument.Styles.Add("Style1", wdStyleTypeParagraph) Dim oControl As ContentControl With oStyle .QuickStyle = True .Font.Underline = wdUnderlineThick .Font.UnderlineColor = wdColorBlack .Font.Italic = True .Font.ColorIndex = wdRed End With For Each oControl In ActiveDocument.ContentControls ''' ''' ??? ''' Next oControl End Sub |
#3
|
||||
|
||||
I'd suggest using a character Style rather than a paragraph Style, as it means you can use this Style in paragraphs that are otherwise formatted differently.
Here's how you can apply it to all Rich Text content controls: Code:
Sub Demo() Dim oStyle As Style, oControl As ContentControl Set oStyle = ActiveDocument.Styles.Add("RTCCStyle", wdStyleTypeCharacter) With oStyle .QuickStyle = True .Font.Underline = wdUnderlineThick .Font.UnderlineColor = wdColorBlack .Font.Italic = True .Font.ColorIndex = wdRed End With For Each oControl In ActiveDocument.ContentControls If oControl.Type = wdContentControlRichText Then oControl.Range.Style = = oStyle.NameLocal End If Next oControl End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] Last edited by macropod; 03-03-2013 at 12:49 AM. Reason: Minor code enhancement |
#4
|
|||
|
|||
What are the differences between Character Style and Paragraph Style? I've been wondering.
|
#5
|
|||
|
|||
Code:
oControl.Range.Style = = oStyle.NameLocal And, After running the codes, I discover in the Properties of the Rich Text Controls. The "use a style to format contents" has not been checked, which means if you type anything inside the formatted Rich Text Controls, the newly typed texts won't be as formatted as expected (in this case, not turned red, still auto black). |
#6
|
|||
|
|||
Yes it was a typo. Paul's code applied the character style to the existing text of the control. To apply it to the control itself, you need to extended the start and end range by 1:
Code:
Sub Demo() Dim oRng As Word.Range Dim oStyle As Style, oControl As ContentControl Set oStyle = ActiveDocument.Styles.Add("RTCCStyle", wdStyleTypeCharacter) With oStyle .QuickStyle = True .Font.Underline = wdUnderlineThick .Font.UnderlineColor = wdColorBlack .Font.Italic = True .Font.ColorIndex = wdRed End With For Each oControl In ActiveDocument.ContentControls If oControl.Type = wdContentControlRichText Then Set oRng = oControl.Range oRng.Start = oRng.Start - 1 oRng.End = oRng.End + 1 oRng.Style = oStyle.NameLocal End If Next oControl End Sub |
#7
|
|||
|
|||
Quote:
Thanks. |
#8
|
||||
|
||||
To learn about Styles, start at: http://office.microsoft.com/en-us/wo...001187614.aspx
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Thanks for the useful reference, macropod.
|
|
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 |
How do you set rich text in a content control | Testor | Word VBA | 4 | 07-08-2012 07:55 AM |
Rich Text Content Control - Allow User Formatting | keithacochrane | Word | 1 | 05-28-2012 05:06 PM |
Grouping Content Controls | cksm4 | Word VBA | 2 | 03-01-2011 12:46 PM |
Templates: automatic text generation from Rich Text content control | Chickenmunga | Word | 0 | 10-01-2008 11:16 AM |