The Best way To Show Code Snippets in MS Word

By phesto on

For those of you who are using Microsoft word for your documents, especially involving code snippets. You might have at one point faced a problem of how to format code snippets preserving its syntax highlight and format.

Here is how I managed to do it, after googling around. I decided to sum up the steps I followed to make it happen.

Here we go.

If by copying code form the IDE to Ms Word does not keep its format, then download Notepad++

Paste your code in the notepad++ window;
 Select the programming language from the language menu;
 Select the text to copy,
 Right click and select Plugin commands -> Copy Text with Syntax Highlighting;
 Paste it into MS Word and you are good to go!

That alone will do the trick, but you might find those annoying spell check and grammar highlights.
If you want to get rid of them and add border around your code, the do the following.

Assuming you are using Ms Word 2010.

To add a border and disable spell check:
 1) select your code;
 2) 'Home->Styles->Save selection as new Quick Style' (it is a drop button, 
or right click the selection area, and select Styles);
 3) Name it 'Code' or similar;
 4) Modify;
 5) Format->Border (lower left) to add border;
 6) Format->Language [X] Do not check spelling or grammar. Now, you can apply 
the same formatting 'Code' to text pasted from Notepadd++

Now you have your nicely formatted code snippet in ms word.

Enjoy.

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

2 comments

  1. This was very useful thanks, I have been using some very othodox methods but this post just made this very easy and looks professional. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>