Word – How to add formatted code to a Microsoft Word document

cmicrosoft wordsource codevb.net

I need to write a document in MS-Word 2007 that contains a lot of examples of VB.NET and C# code.

What is the best way of getting the code to look reasonable in the document?

What styles etc do people use?

(I do not have time to hand edit/format the code, and would be very happy if it just looked the same as it does in developer studio)

In other works what do people do that are writing programming books, there must be a good automated solution for this…

I would like a way to use word styles sheets to control what the code looks like, but don't wish to have to "select" every keyword etc to set it's style.

see also https://stackoverflow.com/questions/387453/how-do-you-display-code-snippets-in-ms-word-preserving-format-and-syntax-highlig/2653406#2653406

Best Answer

You may use source highlighting services and copy / paste to Word document. I think it will be the fastest way (upd. simple copypaste from VS will also works).

The second way is to create a style for code block, save it and then apply to all code blocks.