How to ignore spelling and grammar for certain text styles in Word 2007

Is there a way to ignore spelling and grammar for certain text styles in Word 2007?

Some of the stuff I'm writing is pre-formatted text that looks like this and usually has stuff like if (str.length() != 3) which will give me the squiggly lines on misspelled words like the str in there.


Quick Styles will help you here.

First, select the text for which you want to ignore spelling in your document. Right click and select Styles > Save selection as a new Quick Style. Then click on Modify and a new window will open named "Create new style from Formatting". Set your font type, font size etc. and then click on the Format button which stands on the lower left corner of the window. Select Language option and check "Do not check spelling or grammar" option. Click OK, and OK again. Now you have a style which wil not check spelling or grammar for the font style you determined.