“How do I prevent Word from spellchecking PowerShell code in my training manuals?” is a question I asked myself the other day. I was in the process of reviewing a training guide for managing Azure with PowerShell and here is what my Word document looked like: pages of red error lines:
The spellchecker is working as directed, but we need to give it new directions!
Lines two and four above are the PowerShell code and are the correct syntax for that scripting language. However, most of the code shows up as spelling errors – indicated by the red lines. One solution is to add the commands for PowerShell to your custom dictionary in Word, but that might have impacts on other types of documents you are creating. It would be great it Word knew about the programming languages in the same way it knows about English, Spanish, Chinese etc., but that is not yet the case.
There are a couple of ways to solve this problem. The one I prefer is to create and configure a new formatting style. The advantage of creating a new style is that you can alter font and color for this type of data as well as preventing it being processed by the spell checker.
There is an easy way to create a new text style – just tell Word what you want to do. You may have noticed the following area at the top of Word, Excel and PowerPoint:
Type “Text Styles” in the blue box and follow through the menus to create a new style. You can also find more information on creating new text styles here.
I called my new style “code,” changed the color to blue and selected a different font from the rest of my document so that it would stand out. You should select the formatting that best suits your needs, but before you click OK we have one more step – to turn off the spellchecking for any text formatted with this style. To do this, right-click on the “Format” button in the lower left corner and select “Language” from the menu – as shown in the next screenshot:
You should now see the following screen. You might have a different language selected as your default, but that will not affect our task here. Next check the box “Do not check spelling or grammar,” and click OK.
Below is a sample of the text we started with, formatted as it now appears in my training handbook. You can see that it is now easier to read, review and spot any real spelling errors. The misspelling of “acount” now clearly stands out. It’s also easier to review the blue-colored PowerShell code and visually check for any syntax errors.