Create character style that "imitates" Text Highlight Color

H

Hallsjo

All our templates are locked (limit formatting to a selection of styles...),
and I want to supply the users with a character style that can be used the
same way as the Text Highlight Color tool. I have created a character style
applied a color in the Shading dialogue. This is not the only character style
in the template. There are also styles for bold and italic. The "text
coloring" style works well as long as there are no other character styles
applied to the text. For instance, if I select a word in a paragraph and mark
it as bold using the character style for bold text. If I then I expand the
selection to include both the text marked as bold and other text and apply
the "coloring style", the bold style is removed. If I then reapply the bold
style, the coloring disappears. What I want is to create a style that works
the same way as the Text Highlight Color tool which seems to not affect the
text it is applied to, except for coloring it of course.
 
G

Graham Mayor

Unfortunately styles don't work like that. You would need a macro or allow
the users to apply shading or even to use the highlighter to achieve this
effect.

The macro code to colour the selected text background whilst ignoring the
text formatting would be:

Selection.Shading.BackgroundPatternColor = wdColorYellow

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
H

Hallsjo

Thanks a lot! That seems to work like a charm. A bit cumbersome, but it works
and I am grateful for that. What would the reverse macro look like, i.e. a
macro for removing the color styling (I am not at all familiar with macro
coding). If I use the "clear formatting" command (Ctrl+space) all formatting,
also the initial bold formatting, i removed. It would be helpful to be able
to just remove the color styling.

Again, thanks for a rapid reply to my enquiry.
 
G

Graham Mayor

The following will toggle the backgound colour of the selected text between
yellow and no colour

Sub ToggleYellow()
With Selection.Shading
If .BackgroundPatternColor = wdColorAutomatic Then
.BackgroundPatternColor = wdColorYellow
Else
.BackgroundPatternColor = wdColorAutomatic
End If
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
H

Hallsjo

Again, thanks for a rapid, and functional, reply to my question. This worked
very well and I am grateful.One final question. Am I going about this the
wrong way? Is there a way to selectively activate formatting commands when I
have limited what users can do? In this case I am only interested in allowing
the users to select and markup text in different colours.
 
G

Graham Mayor

I'm afraid that if you are going to cripple the functions available in Word
for some reason, this will be something you have to live with. User training
might be a better plan?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
H

Hallsjo

Yes, I guess you are right. I would like Word to be less blunt when it comes
to limiting what users can do. Anyway, thanks for your help and input which
is most appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top