How to Insert Code Block in Microsoft Word?

The simplest way is to use Paste Special function

Reading time icon 3 min. read


Readers help support Windows Report. We may get a commission if you buy through our links. Tooltip Icon

Read our disclosure page to find out how can you help Windows Report sustain the editorial team Read more

How to Insert Code Block in Microsoft Word?

If you are looking for ways to insert code blocks in Microsoft Word, this guide can help! You can either use the Paste Special as HTML function, insert it as an Object, or use a syntax highlighter to get it done.

How can I insert code blocks in Microsoft Word?

1. Use the Paste Special as HTML function

  1. Press Ctrl + A to select the entire code, then press Ctrl + C to copy it. However, if you want to select a certain part of the code, select it, right-click, and select Copy.
  2. Next, press the Windows key, type word in the search bar, and click Open.Word - insert code blocks in Microsoft Word
  3. On the Word document, go to the Home tab, then click the drop-down under Paste, and choose Paste Special.Paste special
  4. Select HTML format and click OK.HTML: Format - insert code blocks in Microsoft Word

2. Insert an Object

  1. Press the Windows key, type word in the search bar, and click Open.Word - insert code blocks in Microsoft Word
  2. On the Word document, go to the Insert tab, and select Object.
  3. On the Object window, go to the Create New tab, then select OpenDocument Text and click OK.
  4. You will get a new Word document in which you can insert a command or code.
  5. Copy the code from the source, go to the Home tab, then Paste and select Paste Special. Choose HTML format and click OK.HTML: Format - insert code blocks in Microsoft Word
  6. Once you have added the code, close the document. Now, the code will appear in the original document as an object. You can move, resize, and change its border if you want.Object

3. Use a syntax highlighter

  1. First, go to Easy Syntax Highlighter’s webpage and click Get it now to install the add-in for Microsoft Word.Easy Syntax Highlighter tab.
  2. Copy the code from the source and paste the code block.
  3. Now select the code and go to the Easy Syntax Highlighter tab.Click the Highlight selection button.
  4. Click the Highlight selection button.

Alternatively, you can also take a screenshot of the code and paste it as an image on your Word document, however, the drawback to this method will be that you won’t be able to make any changes to the code.

To conclude, you can insert code blocks in Microsoft Word by using Paste Special as an HTML function, insert it as an object, or use a syntax highlighter add-in.

If you want to use Word in your browser, you can try Word online; read this guide to learn more about it in detail.

In case Microsoft Word is not opening on your Windows 11 computer, hop on to these easiest fixes mentioned in this guide.

To give an aesthetic appeal to your Microsoft Word document, you can turn on dark mode on it; check out this quick guide to learn the steps.

If you have any questions or suggestions about the subject, feel free to mention them in the comments section below.

More about the topics: Microsoft Word, word processor