Directions apply to Word 2010 and newer, including Word 2021 and Microsoft 365.

This effectively creates an isolated section that houses all the code.

fire up the document you want the code to appear in, and selectInsert.

A Word document with the Insert field highlighted

In theTextgroup, selectObject.

From theCreate Newtab, selectMicrosoft Word Document.

In Word 2007, selectOpenDocument Text.

A Word document with the Object option highlighted in the Insert menu

Clear theDisplay as iconcheck box.

A new document opens, titledDocument in [target document file name].

Save the document in the same folder as the original document.

Create New Object box in Word with the Microsoft Word Document option highlighted

Copy and paste the source codeinto the new document.

Word automatically ignores the spaces, tabs, and other formatting problems.

Save and wrap up the source code document.

Create New Object window in Word with the OK button highlighted

The code automatically appears in the main document.

you might’t edit this object directly because it’s really just an embedded document.

Double-opt for object to quickly bring up the document with the code.

Microsoft Word displaying source code to insert into a Word presentation document

Using Different Paste Types in Word

Modern versions of Word handle code better than they used to.

Word forMicrosoft 365supports several forms of pasting, including with and without source formatting.

So pasting a block of code from your code-editing app will look different based on the paste throw in.

Microsoft Word document with source code inserted

To keep them on permanently, go toFile>Options>Display>Show all formatting marks>OK.

Alternatively, selectInsert>Links>Linkand enter the URL.

Toconvert a Word document to HTML, go toFile>Save As.

UnderSave as key in, choose.html.

you might also use an editor like Dreamweaver.