Word – Formatting code with line numbers

formattingmicrosoft word

Looking for a way to format my code in MS Word I found this question on Stack Overflow and combined the two high rated answers to create an openDocument with the code keeping its formatting:

  1. Go to "insert" tab, click "object" button (it's on the right)
  2. Choose "openDocument Text": it will open a new embedded word
    document
  3. Open code in Notepad++
  4. Select the programming language from the language menu
  5. In Notepad++ right click and select Plugin commands -> Copy Text with Syntax Highlighting
  6. Paste in to embedded word document
  7. save and close

This works good but I would like line numbers on the code, is there a way to do that?

Best Answer

When the code is in Notepad++, you can use TextFX->TextFX Tools->Insert line numbers to put line numbers in front of all of the necessary lines. Then when you copy/paste, the line numbers will be there.

Related Question