How do you display code snippets in MS Word preserving format and syntax highlighting?

Anonymous
2023-11-06T11:24:17+00:00

Does anyone know a way to display code in Microsoft Word documents that preserves coloring and formatting? Preferably, the method would also be unobtrusive and easy to update.

I have tried to include code as regular text which looks awful and gets in the way when editing regular text. I have also tried inserting objects, a WordPad document and Text Box, into the document then putting the code inside those objects. The code looks much better and is easier to avoid while editing the rest of the text. However, these objects can only span one page which makes editing a nightmare when several pages of code need to be added.

Lastly, I know that there are much better editors/formats that have no problem handling this but I am stuck working with MS word.

Microsoft 365 and Office | Word | For education | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2024-03-03T13:06:40+00:00

    Hey guys!

    I had the same problem, go to file -> Get Add-ins search for: Easy Code Formatter

    It'll do the job :D

    151 people found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2024-02-02T21:37:46+00:00

    There are a number of third-party plugins that can be used to display code snippets in Word with syntax highlighting. One popular plugin is called "CodeHighlighter".

    I couldn't find this plugin. Could you please post a link to it?

    8 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2023-11-06T14:11:04+00:00

    Dear marcuslki,

    Good day! Thank you for posting to Microsoft Community. We are happy to assist you.

    There are a couple of ways to display code snippets in MS Word preserving format and syntax highlighting:

    Method 1: Using the "Keep Source Formatting" option

    1. Copy your code from your code editor.
    2. Right-click in the Word document where you want to paste the code, and select the "Paste Options" button.
    3. In the "Paste Options" menu, select the "Keep Source Formatting" option.
    4. Click "OK" to paste the code.

    This method will preserve the formatting of the code, including the syntax highlighting. However, it can be time-consuming to paste multiple code snippets in this way.

    Method 2: Using a third-party plugin

    There are a number of third-party plugins that can be used to display code snippets in Word with syntax highlighting. One popular plugin is called "CodeHighlighter".

    To use CodeHighlighter:

    1. Download and install the plugin.
    2. Open the Word document where you want to insert the code snippet.
    3. Select the "CodeHighlighter" tab from the ribbon.
    4. In the "CodeHighlighter" tab, select the programming language of the code snippet.
    5. Paste the code snippet into the text box.
    6. Click the "Insert" button.

    CodeHighlighter will insert the code snippet into the document with the appropriate syntax highlighting.

    Method 3: Using a screenshot

    If you are unable to use either of the above methods, you can take a screenshot of the code snippet in your code editor and insert the screenshot into the Word document.

    To take a screenshot:

    1. Open the code snippet in your code editor.
    2. Press the "Print Screen" button on your keyboard.
    3. Open a new image editing program, such as Paint.
    4. Press "Ctrl" + "V" to paste the screenshot into the image editing program.
    5. Crop the screenshot to only include the code snippet.
    6. Save the screenshot as an image file, such as a PNG or JPG.

    To insert the screenshot into the Word document:

    1. Click the "Insert" tab on the ribbon.
    2. In the "Illustrations" group, click the "Pictures" button.
    3. Select the image file containing the screenshot of the code snippet.
    4. Click the "Insert" button.

    The screenshot will be inserted into the Word document.

    Thank you for your precious time. Have a nice day.

    Regards,

    Microsoft Community

    35 people found this answer helpful.
    0 comments No comments