Sometimes I have to write some documentation using Word instead of LaTeX. In LaTeX you have some nice options for typesetting code be it R, Stata or Gams. In Word, however, there is no easy way to format your code. I found a nice way to get my code nicely formatted (in color) using Emacs: I installed the Windows version of Emacs and there I can “Quick Print” – “Preview with Web Browser”. This opens the file as htm in my browser. I now just save this file somewhere on my computer and open it in Word. The text is nicely formatted.
For example some R-Code would look like this in Word:
Have you tried this, it work in other modes
M-x mark-whole-buffer (C-x h)
M-x indent-region (C-M \)