Software & Apps MS Office How to Insert Source Code Into a Word Document It can be done without taking snapshots of each segment By Martin Hendrikx Writer Martin Hendrikx is a former Lifewire writer and an instructor with a background in technology whose work has been published by How-To Geek and other outlets. our editorial process LinkedIn Martin Hendrikx Updated November 10, 2019 MS Office Word Excel Powerpoint Outlook Tweet Share Email Given the way that Microsoft Word structures documents, inserting and working with source code is more difficult than working in a dedicated code editor. However, document embeds create a container that protects source code from being reformatted. Instructions in this article apply to Word for Office 365, Word 2019, Word 2016, Word 2013, Word 2010, and Word 2007. The Problem With Using Source Code in Word Programmers write software programs using languages such as Java, C++, and HTML. Programming languages use different formatting and symbols from regular languages, so pasting a snippet of code into Word from a programming application causes errors such as text reformatting, indentation shifts, link creation, and misspellings. One way to avoid these formatting issues is to paste the source code into a separate document that displays within the main Word document. Embed a Second Document Into a Word Document Here's how to paste source code into a Word document using a second embedded document. These instructions only work with a single page of code. Open the target document in Microsoft Word and place the cursor where the source code will appear. Go to Insert. In the Text group, select Object. In the Object dialog box, select the Create New tab. In the Object type list, choose Microsoft Word Document. In Word 2007, choose OpenDocument Text. Clear the Display as icon check box. Select OK. A new document opens, titled Document in [target document file name]. Save the document in the same folder as the target document. Copy and paste the source code into the new document. Word automatically ignores the spaces, tabs, and other formatting problems. Spelling errors and grammatical errors are highlighted in the document, but when the code is inserted in the original document, these errors are ignored. Save and close the source code document. The source code appears in the main document. Resume work on the main document. Alternative Approaches The most up-to-date versions of Word handle code better than they used to. For example, Word for Office 365 supports several forms of pasting, including pasting with and without source formatting. So pasting a block of code from, for example, Microsoft Visual Studio Code will look different based on the paste type. If you select Paste Special, each of the three options yields a different result: Unformatted Text: All code is pasted as unformatted, so you'll lose indenting, color, typeface, and related contextual clues.HTML Format: From VSC, a paste-as-HTML renders what appears to be a photo of the code, complete with the background color of the text editor. This code block is editable, and you can remove the background color in the Paragraph Fill menu option.Unformatted Unicode Text: Pastes the text as is, but strips the text and background colors. Re-format the code as needed.