MS Word: put syntax highlighed code into the document

Here is the simple method to put the code with highlighting into the Word document:

    1. Download and install Notepad++. This is easy-to-use and yet very powerful text editor with a lot of features, support of the plugins etc.
    2. Put your code into the Notepad++ edit window
    1. Configure the language, if Notepad++ did not do this automatically:
      Language->your language
      npp language select
      If necessary the additional configuration could be done in the Style Configurator: Settings->Style Configurator…
    1. Export the highlighted text with help of NppExport plugin: Plugins->NppExport
      It has the following options:
      npp export options
    1. Select “Copy RTF to clipboard”
    2. Paste the content of the clipboard into the Word document
    3. Make any changes in the Word document if necessary

MS Word: replace spaces to non-breaking

To insert it manually, use Ctrl+Shift+Space


Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Normal")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " "
.Replacement.Text = "^s"
.Forward = True
.Wrap = wdFindContinue
.Format = True
End With
Selection.Find.Execute Replace:=wdReplaceAll