[ms-word] What is the best way to insert source code examples into a Microsoft Word document?

I have tried all your methods, but they didn't work for me, in fact I have created an easier method using MS Word Tables.

Pros:

  1. More beautiful
  2. Easier to manage & more consistent
  3. Are less prone to problems
  4. No need for external plugins or MS Word micro coding.
  5. Easier to handle by simple users (such as myself).

Cons: It will not maintain code colouring although someone could improve my trick.

Steps:

  1. Insert a 3x3 table, in my case I always make the total width of the table equals the free page's width (3 rows minimum to test the tables style).

  2. Use invisible borders ("No Borders" option), and activate "View Gridlines" option. it should have this aspect. Be ware that those lines are for you to see the table's grid, and the will not be printed.

enter image description here

  1. Make the adjustments to cells' spacing and columns' width to get the aspect you like. (You will have to get in "Table Properties" for fine tuning). enter image description here

  2. Create a "Paragraph Style" with the name of "Code" just for your code snippets (check https://stackoverflow.com/a/25092977/8533804 to get the idea, you don't have to follow all of it)

  3. Create another "Paragraph Style" with the name of "Code_numberline" that will be based upon the previous created style. enter image description here

  4. In the newly created "Code_numberline" add the numbering style that you like (this will automate line numbering). enter image description here

  5. Apply "Code_numberline" to the first column, and "Code" to the 3 column. enter image description here

  6. Add a fill in the middle column. enter image description here

  7. Save that table style and enjoy!