3

How do I prevent a style from changing the font color. I have "Automatic" selected as the font color (and the "Default" button under "Font" is disabled by the way), but whenever I apply the style, the font color changes to black. Using Word 2007

4 Answers 4

3

A style is intended to modify the appearance of the text it is applied to, including colour. You don't want to stop it from doing that. If you don't like the colour it is applying, you should change the style itself. If you want to keep the old style for other documents, but change the colour for a specific document, just make a copy of the style, modify the copy and apply the modified style instead of the original one.

To make a new style, go to the start tab. In the ribbon, there is a section called Styles. In the lower right corner, there is a UI element, a small right angle with an arrow pointing away from it. Click it, and you'll see a floating window listing all styles. Select the style you want to change from the list. Under the list, there are three buttons. If you want to make a copy based on the old one, select the button for creating a new style. If you want to change the old one, select the button for managing styles. A new window opens with yet another list of styles, where your style is still selected. About the middle there is a modify button, click it.

In both cases, you see a new window where you can modify the (new copy of the) style. Under Format, there is a drop-down box where you can select the font colour you like. Choose the colour you like, save your changes and you're done.

If you have a corporate colour scheme and want to use the standard Word 2007 layouts but with your own colour scheme, there is an easy way to do that. In the Styles section of the ribbon under the Start tab, there is the big button called "Change styles". Clicking it opens a small menu. Select colours, and you are given the choice of the typical Word 2007 colour schemata. At the bottom, there is a option called "Create new design colours". There you can set colours for different purposes. Choosing the scheme will change the colours of the standard styles to the new ones, and you can always go back to standard by choosing the "Larissa" integrated colour scheme again.

Disclaimer: As I had to backtranslate from my non-english Word, maybe I've gotten the names of some UI elements wrong, but I guess it will be easy to find them.

edit re: your comment

Styles are meant to change the formatting of text, I don't think there is a way to stop this behaviour. However, I don't see a reason for applying a style at all. Just paste the code and select the option to preserve the original formatting. I just tried with code from Eclipse, I think it will support formatting from other IDEs too.

Also, whatever you are doing, maybe you're trying to solve your problem in the wrong way. I hope you aren't trying to program in Word. If you're writing some sort of coding tutorial, why do you need the code as text? You could include the examples as screenshots. Or you could write the whole thing in LaTeX (if you know LaTeX or if your layout is basic enough), because there are ways to syntax highlight code snippets in LaTeX, or to generate syntax highlighted LaTeX source from a source code. Or if you're that desperate, make the whole thing in HTML. Use CSS for the layout of the generic text surrounding the code, then feed your code through something like Pygments, and paste the HTML output directly into your document; the HTML tags formatting should overwrite the CSS style.

Of course, maybe I'm wrong and there is a way to apply a style in Word without changing the font colour. But I doubt it, it would go against the very purpose of styles.

3
  • 3
    Ahh but see my problem is that that the text that I wish to apply the style to has multiple colors (it is actually source code with formatted coloring, certain bolded words, etc. So I can't set one color for the style, I need it to simply accept whatever color and bold, etc. it encounters and not change it, and only make changes to what I explicitly instruct it to (in this case special numbering, background color, and indentations)
    – WaelJ
    Commented Mar 26, 2010 at 19:21
  • Yes I do preserve the original formatting when pasting (with the color and bold, etc.) It turned out not to be such a big problem. Applying the style would only modify the first color it encounters, so if I have say a couple green words, and then a blue words, etc... , then applying the style to that block of text would change the initial green words to black, and the rest would remain as it is. So I simply applied the style to each section and then manually changed the color of that first bit. Weird implementation of styles if you ask me :S Thank you for your extended response ;D
    – WaelJ
    Commented Mar 27, 2010 at 12:27
  • This would be acceptable, if there was a way to prevent spell checking on a section of code. Currently, AFAIK, the only non-manual way of doing this is to embed it into a style. Commented Nov 1, 2011 at 15:17
8

Not sure if this is even remotely reliable, but I have discovered that if I copy/paste syntax highlighted code from Visual Studio 2010 into Word 2010, then select the line just above the code block with it before applying a style to it, then the colours are preserved.

I'm inclined to agree with what rumtscho's answer says with regard to how styles should behave, so I wouldn't depend on this - seems like a bug (but it may be useful to someone). Different versions of Word etc. may well behave differently...

2
  • 3
    This worked for me - thanks. I realized that Word tries to work out what's 'normal' by looking at the first word or first line - anything that matches this will be replaced with the new styling. So if I add a new line and set the color of it to something NOT used in the code block, Word doesn't try to change the color of the rest of the block. Commented Oct 24, 2012 at 11:51
  • That's the actual solution to the OP's problem. As you say, that may not be indefinite, but nothing is with the way Microsoft deals with their software, so it seems to be an acceptable solution for now. Thanks a lot!
    – RedGlyph
    Commented May 19, 2018 at 15:02
0

gmaclachlan's answer worked for me as well (in Word 365, Version 1703). Thanks very much! Just as Ian said, the color of the above line needs to be set to something not in the code block. So as long as your font color is set to black and the code doesn't start with black text, the colors shouldn't change when applying the style. This can actually be used to replace colors inside a block if used correctly. For example, if you have

This is code
<script src="main.js></script>
that does stuff

with <script, >, </script> in dark blue, src="" in light blue and main.js in green and you want to replace all the greentext with pink text, just copy the style from src=" to "code", select everything from "code" to </script> and apply a style with the desired text color specified. This replaces all green text with pink text. (For this to work correctly, make sure that your "color modification style" inherits no properties from any other style).

0

The accepted answer above is very long, doesn't really solve the OP's problem, and completely disregards that it is very common to want to paste source code into Microsoft Word with wanting to modify a lot of styling aside from the highlighting; such as borders, background color, indentation, font size, etc... which could all be done manually of course but would be very boring compared to one click on a custom style...

Until now there doesn't seem to be a proper solution to the OP's problem that I know of, but there's a workaround that is actually mentioned in the previous answers/comments but not in a very clear or reliable method/process (hence my answer)


The workaround that works for me on Office 2019 is to:

  1. Paste the source code from your text editor or IDE as-is into your document
  2. Move your cursor to the beginning of the first line and press ENTER
  3. Move your cursor to the newly created empty line
  4. Change that line's color to some color that is not used elsewhere in the code (usually Word's default red isn't used)
  5. Type anything (I personally just press "a")
  6. Select the entire code including the newly created line and apply the styling (at this point only the newly created line will have its color changed, but none else)
  7. Remove the extraneous first line

This apparently abuses some bug(?) in Word's styling behavior where it changes any and all instances of the first encountered color to the color defined in that style but none else. Since we tricked it into changing a color that isn't used in the code altogether, your source code should be safe.

Extra: If for some reason you want to override this behavior, you can double click on the style to force the color over all the text in the pasted content.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .