Skip to content
Fix Code Error

How do you display code snippets in MS Word preserving format and syntax highlighting?

March 13, 2021 by Code Error
Posted By: Anonymous

Does anyone know a way to display code in Microsoft Word documents that preserves coloring and formatting? Preferably, the method would also be unobtrusive and easy to update.

I have tried to include code as regular text which looks awful and gets in the way when editing regular text. I have also tried inserting objects, a WordPad document and Text Box, into the document then putting the code inside those objects. The code looks much better and is easier to avoid while editing the rest of the text. However, these objects can only span one page which makes editing a nightmare when several pages of code need to be added.

Lastly, I know that there are much better editors/formats that have no problem handling this but I am stuck working with MS word.

Solution

Here is the best way, for me, to add code inside word:

  1. go to Insert tab, Text section, 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.

Answered By: Anonymous

Related Articles

  • What's the difference between eval, exec, and compile?
  • data.table vs dplyr: can one do something well the other…
  • Ukkonen's suffix tree algorithm in plain English
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • Is it possible to apply CSS to half of a character?
  • How to filter a RecyclerView with a SearchView
  • What is a NullReferenceException, and how do I fix it?
  • What are the undocumented features and limitations of the…
  • What is your most productive shortcut with Vim?
  • For-each over an array in JavaScript

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How to kill a process running on particular port in Linux?

Next Post:

What is the best IDE for PHP?

Leave a Reply Cancel reply

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

  • Get code errors & solutions at akashmittal.com
© 2022 Fix Code Error