How to insert Code Blocks and Commands in Microsoft Word

In most cases, folks tend to use Notepad to add code blocks and commands, but if you already have Microsoft Word opened, then there is no need to fire up Notepad at all. From what we can tell, Microsoft Word is just as good, if not better, if you know how to paste commands and code blocks. let us see how to add Code Blocks and Commands in Microsoft Word.

How to display Code Blocks and Commands in Word

Now, there are several ways to insert code blocks and commands to Word, but not a significant number. It all boils down to whether you want the reader to have the ability to copy the contents or just to view them. As expected, we are going to discuss how to accomplish each task. Worry not because everything will be easy to understand.

  1. Copy the code block or command
  2. Open Microsoft Word
  3. Paste content as HTML
  4. Insert code as an object
  5. Use Easy Syntax Highlighter

1] Copy the code block or command

Wherever you have the code block or command saved, you must copy the relevant content before we can send it over to Microsoft Word.

  • Press CTRL + A to highlight to the code.
  • From there, hit CTRL + C to copy everything.
  • Alternatively, use the keyboard to highlight a certain section of the code.
  • Then press CTRL + C to copy.

2] Open Microsoft Word

The next step to take here is to open a blank Microsoft Word document. This is where we will paste the code block or command recently copied.

  • Open the Word application from the desktop or via the Apps section.
  • From the main menu, please click on Blank Document.

You should now be looking at a blank document ready to be populated with content.

3] Paste content as HTML

How to add Code Blocks and Commands in Microsoft Word

If you want folks to copy the command or code block from your document, we suggest using the Paste Special as HTML feature. This is one of the fastest ways to add such content to a Word document as it inserts the code without using another formatting of the document.

  • Place the mouse cursor to the section where you want the code to appear.
  • Navigate to the Home tab.
  • After that, you must click on the Paste button found on the Ribbon.
  • Via the dropdown menu, please select Paste Special.
  • Select the option that reads, HTML Format.
  • Hit the OK button.
  • The code block or command should now be visible in HTML format.
  • Return to the Home tab to color the specified section of your code if you wish.

Easy, right? We agree.

4] Insert code as an object

Microsoft Word Object

This option is for those who want to share their code or command with others, but without giving the ability to copy. Viewers can only look, but cannot touch, though that does not stop them from taking screenshots.

  • Find the Insert tab in Microsoft Word
  • You must now click on the Object icon.
  • From the dropdown menu, select Object.
  • A new window known as Object should now appear.
  • From that window, please select OpenDocument Text.
  • Hit the OK button.
  • A new document window will load.
  • You can now paste the copied code block or command into this new document.
  • Finally, close the document.

If all goes according to plan, the code or command should show up in the original Word document as an Object.

5] Use Easy Syntax Highlighter

Highlight Selection Microsoft Word

If you want to highlight your code blocks and commands, then we suggest downloading the Microsoft Word add-in known as Easy Syntax Highlighter. Visit the official page to get it on your system right now.

  • Now that the add-in is up and running, paste the code block or command.
  • Select the command or code.
  • From there, go to the Easy Syntax Highlighter tab.
  • In order to deploy the default formatting, click on Highlight Selection.
  • Your snippet will be selected and text formatted.

ReadHow to Warp and Convert multiple Words to one Shape in Illustrator

How do I insert HTML code into a Word document?

Inserting HTML codes into a Word document is a simple task if you know what you’re doing.

  • All you have to do is open a blank Word document.
  • Got to the Insert tab.
  • Navigate to the Text section.
  • Click on the Object icon.
  • Select Text From File.
  • Take advantage of the file type selector from the Insert File box.
  • Choose the All Web Pages option.
  • Convert File box should now appear.
  • Select Other Encoding.
  • Finally, hit the OK button.

Can you write code in Microsoft Word?

You can write whatever you want in Microsoft Word because after all, it is a word processing tool. Still, tools such as Notepad will always be best for writing code due to their simplicity and specialized features.

How to add Code Blocks and Commands in Microsoft Word

Source link

Alice AUSTIN

Alice AUSTIN is studying Cisco Systems Engineering. He has passion with both hardware and software and writes articles and reviews for many IT websites.

Leave a Reply