Syntax Highlighting In MS Word For C# & SQL To Make Code Clean & Easier For Blogging

I would like to share some tips that how we can use syntax highlighting in MS word. Developers and bloggers have to look into syntax highlighting on daily basis or at least once in a week.

Syntax highlighting is one of the most useful feature for a blogging website. If we are looking into the code and any website it is not using Syntax highlighting then more than 50% developer will not prefer to read the complete article.

In the same way we can highlight our C#, JavaScript, SQL, HTML, XML and other languages codes & syntaxes. I am giving an example of csharpcorner.com editor so that it is easier for authors to publish formatted clean code.

Also, it will be helpful for bloggers and developers both, so let us see how we can use it.

Normal Syntax Highlighting

Normal Syntax Highlighting

Expected Syntax Highlighting

Expected Syntax Highlighting

Let’s see the reason why we need this. In the following image you can see that I have copied some text from Visual Studio and paste it in MS word and Syntax highlighting also applied here.

Visual Studio

But this Syntax Highlight is having issues. The issue is that Spell checking has been enabled in MS word and showing me a lot of red underlines. To fix this we need to go spell check and then either we need to ignore these words or add it to dictionary. It very irritating and time consuming. So let us use another way of syntax highlighting.

Step 1: Click on the line inside the MS Word Document where you want to put your C# or SQL code.

Step 2: Click on Insert Menu.

Step 3: Click on Object.

object

It will open a new window. 

object1

Step 4: Select OpenDocument Text and click on OK.

object2

It will open a new window (in fact a new MS word document) for pasting your code.

Step 5: Paste you code inside the new document; Save and close the document. Now your parent MS word document will look like the following screenshot.

auto properties initializers
You can see in the above screenshot that code is very neat and clean as compared to older one.

You can also use this syntax highlighting feature when copying data from Notepad++.

Syntax highlighting while copying data from Notepad++

Repeat the same step as mentioned above but you may be wondering that in above example we have copied text from Visual Studio. That’s why syntax highlighting was maintained. But while copying data from Notepad++ syntax is not being highlighted.

So to copy the text from Notepad++ with syntax highlighting do the following things:

Step 1: Go to language menu and choose the appropriate language,
language

Step 2: Select all the contents of the file using Ctrl+A, then go to Plugins Menu—NPPExport—Copy all formats to clipboard.

plugins

Now you can paste the above code for highlighted syntax in MS Word.

Now let’s see how we can copy and paste the highlighted Text in HTML editors:

Step 1: Open any website where you want to put it. Let's say I opened the following Link,

Go to Blog Details Section and open the Syntax Highlighter code Window.

syntax highlighter

Now double click on the code written in MS word and it will open the code in a new document, copy the code and paste it in “Syntax Highlighter code Window of c-sharpcorner.com”.

It will look like the following screenshot,
screenshot

Up Next
    Ebook Download
    View all
    Learn
    View all