DevX has posted an article that I am really pretty proud of: a literate programming tool for .NET using Microsoft's Visual Studio Tools for Office 2005. By using Word styles and embedding XML tags, you can label your code fragments in a Word document as compilable (including specifying assembly targets, compiler options, etc.). Additionally, the code fragments can have references to other code fragments within them, so that your code fragment can say “\<\<using block>>” and you can fill in those details someplace else in the document (in a separate discussion, an appendix, or even in a hidden “boilerplate“ section).
A SmartTag assembles all of the code fragments for a given “compilation unit,“ (think normal source code file) and all the “compilation unit“s for a given “assembly target.“ They source can be placed on the clipboard as an XML tree of fragments, as an assembled compilation unit (ready for pasting into Visual Studio), or can even be compiled directly from within Word. I support C# and VB.NET “out of the box“ but it's a simple matter to support additional languages for compilation.
Normally, I'm content to write a tool for an article and leave it for as inspiration for further exploration by others, but I think this tool has such potential that I'm going to continue developing it, possibly on SourceForge or, more likely, hosted locally. In particular, I'd like to add FIT capabilities so that authors would have the ability to confirm that their code behaves as they expect; macros so that adding code blocks was as easy as “Ctl-C“ (or whatever); and the ability to specify “alternate fragments“ so that you can say “If we replace Listing 12 with Listing 13, you can see the behavior do such-and-so...“
I'm going to reveal a new site on the subject shortly...