How to properly Show Code Snippets in MS Word?

9,292

From StackOverflow:

  1. go to "insert" tab, click "object" button (it's on the right)
  2. choose "openDocument Text" which will open a new embedded word document
  3. copy and paste your code from Visual Studio / Eclipse inside this embedded word page
  4. save and close

The result looks very nice. Here are the advantages of this method:

  • the code keeps its original layout and colors
  • the code is separated from the rest of the document, as if it was a picture or a chart
  • spelling errors won't be highlighted in the code (this is cool!)

And it takes only few seconds.

Note of mine (after checking this solution), just to clear: After inserting the object Word will open a new instance, which is the code snippet. Just paste the code, save and close. If you will want to edit the code just double-click the snippet and Word will open the document.

You may also consider the other solutions which were presented by other users for this question.

This solution is good for any kind of snippet.

Share:
9,292

Related videos on Youtube

YathuGulan Uthayan
Author by

YathuGulan Uthayan

Updated on September 18, 2022

Comments

  • YathuGulan Uthayan
    YathuGulan Uthayan over 1 year

    I want to show code snippets with the original formatted styles in Microsoft Word document, is there anyway to do this?

    The code is:

    <iframe class="codetidy" type="text/html" width="100%" src="http://codetidy.com/paste/embed/6130" frameborder="0"></iframe>
    
  • matan129
    matan129 almost 11 years
    Yeah. But he wouldn't be able to edit the code within word. No so convenient.