How to Insert Code Block in Microsoft Word?
The simplest way is to use Paste Special function
3 min. read
Published on
Read our disclosure page to find out how can you help Windows Report sustain the editorial team Read more
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
- 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.
- Next, press the Windows key, type word in the search bar, and click Open.
- On the Word document, go to the Home tab, then click the drop-down under Paste, and choose Paste Special.
- Select HTML format and click OK.
2. Insert an Object
- Press the Windows key, type word in the search bar, and click Open.
- On the Word document, go to the Insert tab, and select Object.
- On the Object window, go to the Create New tab, then select OpenDocument Text and click OK.
- You will get a new Word document in which you can insert a command or code.
- Copy the code from the source, go to the Home tab, then Paste and select Paste Special. Choose HTML format and click OK.
- 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.
3. Use a syntax highlighter
- First, go to Easy Syntax Highlighter’s webpage and click Get it now to install the add-in for Microsoft Word.
- Copy the code from the source and paste the code block.
- Now select the code and go to the Easy Syntax Highlighter tab.
- 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.