Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-02-2013, 10:49 PM
tinfanide tinfanide is offline Rich Text Content Controls: Formatting? Windows 7 64bit Rich Text Content Controls: Formatting? Office 2010 32bit
Expert
Rich Text Content Controls: Formatting?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 03-03-2013, 12:15 AM
tinfanide tinfanide is offline Rich Text Content Controls: Formatting? Windows 7 64bit Rich Text Content Controls: Formatting? Office 2010 32bit
Expert
Rich Text Content Controls: Formatting?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

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
Reply With Quote
  #3  
Old 03-03-2013, 12:46 AM
macropod's Avatar
macropod macropod is offline Rich Text Content Controls: Formatting? Windows 7 64bit Rich Text Content Controls: Formatting? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
If you only want to apply it to some Rich Text content controls, you'll need additional rules you can test with If statements. For example, any one or more of the Section of the document, the Rich Text content control's title, a bookmarked range could be used.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 03-03-2013 at 12:49 AM. Reason: Minor code enhancement
Reply With Quote
  #4  
Old 03-03-2013, 05:04 AM
tinfanide tinfanide is offline Rich Text Content Controls: Formatting? Windows 7 64bit Rich Text Content Controls: Formatting? Office 2010 32bit
Expert
Rich Text Content Controls: Formatting?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
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.
What are the differences between Character Style and Paragraph Style? I've been wondering.
Reply With Quote
  #5  
Old 03-03-2013, 05:15 AM
tinfanide tinfanide is offline Rich Text Content Controls: Formatting? Windows 7 64bit Rich Text Content Controls: Formatting? Office 2010 32bit
Expert
Rich Text Content Controls: Formatting?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Code:
oControl.Range.Style = = oStyle.NameLocal
Is it a typo of the "= ="?

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).
Reply With Quote
  #6  
Old 03-03-2013, 06:43 AM
gmaxey gmaxey is offline Rich Text Content Controls: Formatting? Windows 7 32bit Rich Text Content Controls: Formatting? Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 03-03-2013, 07:19 AM
tinfanide tinfanide is offline Rich Text Content Controls: Formatting? Windows 7 64bit Rich Text Content Controls: Formatting? Office 2010 32bit
Expert
Rich Text Content Controls: Formatting?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
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:
Ya're right. Start - 1 and End + 1 works like a magic.
Thanks.
Reply With Quote
  #8  
Old 03-03-2013, 01:30 PM
macropod's Avatar
macropod macropod is offline Rich Text Content Controls: Formatting? Windows 7 64bit Rich Text Content Controls: Formatting? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

To learn about Styles, start at: http://office.microsoft.com/en-us/wo...001187614.aspx
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 03-04-2013, 04:15 AM
tinfanide tinfanide is offline Rich Text Content Controls: Formatting? Windows 7 64bit Rich Text Content Controls: Formatting? Office 2010 32bit
Expert
Rich Text Content Controls: Formatting?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Thanks for the useful reference, macropod.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Rich Text Content Controls: Formatting? Rich text/Plain text Content Controls in Template michael.fisher5 Word 9 11-19-2014 06:36 AM
Rich Text Content Controls: Formatting? How do you set rich text in a content control Testor Word VBA 4 07-08-2012 07:55 AM
Rich Text Content Controls: Formatting? Rich Text Content Control - Allow User Formatting keithacochrane Word 1 05-28-2012 05:06 PM
Rich Text Content Controls: Formatting? 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:40 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft