235

I'm using Notepad++ to write code.

How do I copy code in Notepad++ along with its formatting to paste into Microsoft Word? (i.e. syntax highlights, etc)

1

10 Answers 10

327

Here is an image from notepad++ when you select text to copy as html.

Notepad++ Plugin: Copy as HTML

and how the formatted text looks like after pasting it in OneNote (similar to any other app that supports "Paste Special"): How it looks like when importing it

7
  • 4
    "Export to HTML" works but not "Copy HTML to clipboard". Do you know why?
    – Pacerier
    Commented Jul 3, 2015 at 9:53
  • 14
    A shortcut is to use: Ctrl + Shift + C. Settings > Shortcut Mapper > Plugin Commands > Copy all Formats to clipboard. > CTRL+SHIFT+C --> Happy formatting !
    – The Beast
    Commented Oct 29, 2016 at 18:38
  • 7
    anyone loose Line Feed using this method?
    – BobNoobGuy
    Commented Mar 13, 2017 at 22:28
  • 1
    @BobNoobGuy I am when I try to use "Copy HTML to Clipboard" (I'm on 7.2.2). Although hackish, the way I preserve line feed is by exporting to HTML, opening the HTML in Word, then copying from there to whichever source I need to send code to (e.g. OneNote).
    – Joe Greene
    Commented Mar 14, 2017 at 2:07
  • 1
    this method is no longer preserving the format color
    – Homer
    Commented Nov 13, 2019 at 21:49
76

Taken from here:

You can use Notepad++ to accomplish this in three ways. Just so you know, Notepad++ is a more advanced version of Notepad, which supports syntax highlighting of different code files "out of the box" - PHP included!

Download & install it, fire it up, and load up your PHP file. You should automatically see it beautifully coloured (if not, because the file extension is something other than .php, go to Language -> PHP or Language -> P -> PHP).

If you need to change any of the colours, you can easily do so - just go to Settings -> Styler Configurator. From that menu, you can change the various highlighting and font options, to suit your needs - although the default usually suffices for most.

Then, go to Plugins -> NppExport. From there, you have three options you can consider:

Export to RTF Export to HTML Copy all formats to clipboard Start with the last one - "Copy all formats to clipboard" - which will copy the entire file with the highlighted syntax to the clipboard. Once you click it, then open Microsoft Word, and just hit paste! You should see the beautifully syntax-highlighted code. If something goes wrong, then you can try one of the other options (export to RTF/HTML), although I've never had a problem with the clipboard method.

4
  • 46
    And now go to [Settings > Shortcut Mapper > Plugin Commands > Copy all Formats to clipboard] and set it to CTRL+SHIFT+C --> Instant joy. CTRL+C to copy the raw text, CTRL+SHIFT+C to copy with formatting. This should be default.
    – Dennis G
    Commented Nov 8, 2012 at 8:39
  • for paste with formatting use CTRL+SHIFT+V in libreOffice writer Commented Jul 13, 2014 at 13:49
  • 3
    @DennisG, Instant joy, until you are at your colleague's desk (or anyone else for that matter) and you found yourself so used to CTRL+SHIFT+C that you've forgotten where the original setting is located. Whoops.
    – Pacerier
    Commented Jul 3, 2015 at 10:05
  • 1
    This worked for me except I was trying to preserve formatting in a Notepad file instead of an MSWord file. I had to copy the code from Notepad++, paste it into MSWord and then copy it from MSWord and paste it into Notepad. For some reason I could not paste it directly into Notepad. Commented Jul 9, 2016 at 13:21
35

Select the Text

From the menu, go to Plugins > NPPExport > Copy RTF to clipboard

In MS Word go to Edit > Paste Special

This will open the Paste Special dialog box. Select the Paste radio button and from the list select Formatted Text (RTF)

You should be able to see the Formatted Text.

0
21

Select the text.

Right Click.

Plugin Commands -> Copy Text with Syntax Highlighting

Paste it into Word or whatever.

12

It is worth mentioning that 64-bit Notepad++ does not support Plugin Manager and NPPExport, so they won't be shown in Plugins menu. If you will try to add NPPExport plugin manually, most likely you'll see :

"NPPExport plugin is not supported with 64bit Notepad++"

Fortunately, there is NPP_Export plugin to download from here which works well with 64-bit Notepad++ (v7.2.2 in my case) and support for Plugin Manager is underway (check GitHub for updates).

10

It seems to me that the best and easiest way is commented by Dennis G:

And now go to [Settings > Shortcut Mapper > Plugin Commands > Copy all Formats to clipboard] and set it to CTRL+SHIFT+C --> Instant joy. CTRL+C to copy the raw text, CTRL+SHIFT+C to copy with formatting. This should be default.

Hoping help someone just like me!

1
  • This is quite helpful, however, in my case, line endings and font types are not saved.
    – specstr
    Commented Dec 20, 2020 at 13:24
6

For those who do not see Plugins->NPPExport,

Download Plugin Manager from this. Extract contents and place under C/ProgramFile/NP++ installation, plugins & updater folder. Restart NP++. You should be able to see Plugins->Plugin Manager then. You can download any plugin, including NPPExport and install it to see the Copy command.

3

As the chosen answer is pretty old, and things changed, here is the new procedure, if you use 64 bits Notepad++. 64 bits version does not come with Plugin Manager nor NppExport. All details provided here.

To resume quickly, Plugin Manager is no longer develloped and NppExport can be found just here.

-1

I practised almost all methods sent by other users in this thread but in my opinion my solution works perfect. I pasted even content from Notepad++ but supports only one font. I decided to use native programs desired to make apps. I set in every code editor (Visual Studio, Intellij Idea, Android Studio, etc) my fav font so I copy source code from my environment program and paste code formatting to my documentation together (with font also). Looks great and clear The first image shows the view in Android Studio. screenshot from Intellij Idea

The second image shows the pasted source code. I just copied the selected part of source code and pasted to my document editor. screenshot from document editor

2
  • 2
    The images appear to show the results of your solution, but you have not described your solution or how to use it!
    – AdrianHHH
    Commented Mar 15, 2021 at 12:23
  • I updated the description
    – baobab159
    Commented Mar 18, 2022 at 8:55
-4

Horrible to look for this failure:

Copy .dll to here:

\Program Files\Notepad++\plugins --> put it here

Restart the notepad++

and now you are able to use the copy commands!!!

1
  • 3
    What DLL would that be? Commented Nov 1, 2017 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.