How to Insert Multi-Page Code with Syntax Highlighting in Word
Question details
The user wants to insert multiple pages of source code into a Word document while retaining the original formatting, syntax highlighting, and editability.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Writing technical documentation, reports, or manuals that require long snippets of readable programming scripts.
- Observed behavior
- Standard pasting removes syntax highlighting, triggers disruptive spelling and grammar errors, and often fails to maintain clean multi-page alignment.
Ensure you have your original source code open in an advanced text editor like Notepad++ or Visual Studio Code, as these tools help format and prepare the syntax highlighting before transferring to Word.
Paste Code as Formatted RTF from a Text Editor
This is the most reliable method to keep original syntax highlighting, colors, and multi-page flow without needing extra Word add-ins.
Advanced text editors have built-in features to export code along with its visual formatting as Rich Text Format (RTF). When this RTF is pasted into Word, it translates perfectly into standard text with all colors and line breaks intact.
Launch an editor like Notepad++. Ensure your code is properly recognized and highlighted according to its programming language.
In Notepad++, navigate to 'Plugins' > 'NppExport' and select 'Copy RTF to clipboard'. In other editors like VS Code, copying the text naturally copies the RTF data by default.
Open your Microsoft Word document. Right-click the destination area and choose 'Keep Source Formatting' under the Paste Options.
Verify that the text flows correctly across multiple pages. The code is fully editable and searchable.

Use a Word Code-Formatting Add-in
Ideal if you frequently paste raw code directly into Word and want to apply syntax highlighting and line numbers on the fly.
Create a Custom Code Style and Disable Spell Check
Best for simple, single-color code snippets where you just need proper monospaced alignment and want to remove distracting red underline errors.
Format Technical Documents Effortlessly with WPS Writer
WPS Writer provides robust styling options and flawless RTF pasting capabilities, making it incredibly easy to include multi-page, syntax-highlighted code in your technical reports and documentation.
- 1. Copy your code: Highlight and copy your source code from your preferred code editor, ensuring it copies the rich text formatting.
- 2. Open WPS Writer: Launch WPS Office and open your existing document or create a new technical report.
- 3. Paste with original formatting: Right-click in the document, select 'Keep Source Formatting', and watch your colorful, highlighted code appear perfectly.
- 4. Customize paragraph settings: Select the code block and adjust spacing or proofing language within WPS Writer's intuitive sidebar to finalize your layout.

Frequently Asked Questions
Why does my source code have red underlines in Word?
Microsoft Word treats programming syntax and variables as misspelled words. You can fix this by highlighting the code, going to Review > Language > Set Proofing Language, and checking 'Do not check spelling or grammar'.
Can I insert code as an object to keep its formatting intact?
Yes, you can go to Insert > Object and choose an OpenDocument Text object. However, embedded objects typically cannot flow across multiple pages, meaning long snippets of code will be cut off at the bottom of the page.
Should I just use screenshots for my code?
While taking a screenshot guarantees the formatting looks perfect, it is not recommended for multi-page code. Images cannot be edited later, are not searchable within the document, and are inaccessible to screen readers.
What is the best font for displaying code in a document?
Monospaced fonts are the standard for code because every character takes up the exact same width, maintaining proper indentation. Popular choices include Consolas, Courier New, Lucida Console, and Cascadia Code.




