Is it possible to copy code from Visual Studio and paste formatted code to OneNote?

Is there a way to copy code from visual studio (C#) and paste it into OneNote, without losing the formatting?

I was able to do this, but only if I copy from VS, paste to Word, copy from Word, and then paste to OneNote.


There is fortunately a solution for Visual Studio 2010! Install the Visual Studio 2010 Pro Power Tools extension and copy/paste to OneNote retains syntax highlighting.


This is an option that seems to be disabled by default.

To enable (in VS 2019):

  1. Go to Tools -> Options

  2. type copy in the search box

  3. Under Text Editor -> Advanced...

  4. Check Copy rich text on copy/cut

Visual Studio Options Example

Top copy as formatted

Once the feature is enabled, depending on the target, this may be a two-step process. If, after copying and pasting code, it still appears as unformatted (e.g. if pasting into a web browser), use the approach suggested by marcus, by first pasting into wordpad.exe (start -> run -> type wordpad), then copying the text from within Wordpad again, and pasting into the target application/browser.


You have hit the nail on the head on the process. The application that you are pasting to must be able to accept the code with the formatting properly. MS Word is one of the few that handles this properly, therefore, going from VS -> Word -> OneNote will work. But VS -> OneNote doesn't work.


For Visual Studio 2008 ---- http://blogs.msdn.com/b/johnguin/archive/2010/11/29/an-addin-to-help-visual-studio-users-with-moving-code-to-onenote.aspx


There is an add-in for Microsoft Visual Studio that allows you to copy source code, syntax highlighting, and line numbers as HTML.

With this add-in, you can copy from VS and paste HTML directly to your target.

Check it out here: CopySourceAsHtml