To insert code in Word, you cannot use the copy and paste operation as with normal text and documents, but need to use the Paste Special option or insert as an object. We will need to paste the code block inserted in Word as HTML or insert Object to display the correct code format in Word. The following article will guide you to insert code in Word.
How to insert code block in Word using Paste Special
Step 1:
You open the Word document you want to insert the code block into the interface. Next, you copy the code block you want to use as usual.
Step 2:
Return to the Word document, click on the Home tab and look down, in the Paste tool we select Paste Special .

Step 3:
Display the paste content option, we click on HTML format and then click OK to paste the code into the Word document.

Immediately after that you will see the code inserted in Word as shown below.

How to insert code in Word via the Insert tab
Step 1:
On the Word interface, click on the Insert tab to insert an object. Then, look down at the Text group, select Object , and then click Object in the drop-down list.

Step 2:
Displays the interface for selecting the type of object you want to insert into Word. Click on the Create New tab , then look down and click on OpenDocument Text and OK.

Step 3:
Now a Word document is opened and you also click on the Home tab then Paste select Paste Special . Next we choose HTML format and click OK to paste the code . Then you close this newly opened Word document without saving .
Go back to the Word document, insert the code and you will immediately see the code as shown below.
