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

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.

Leave a Comment