How to format code in a thesis (Word document)?
You should create a paragraph style with the appropriate settings—a monospaced font for one thing, probably some indentation—and use that.

When using Microsoft Word you should resist the temptation to change any properties of the font at all manually. (Ideally remove the font bar from the ribbon altogether.) Instead you should create paragraph and character styles and apply them as you go along. Then they can easily be edited globally later.

If you really need syntax highlighting, the "best" way would probably be to write a macro that tagged the different parts of the code with a different character style for each code element, and then adjust the colours in the character style editor later. Then run the macro on each code block. I suspect such a macro probably exists somewhere.

The "quick" way would be to copy and paste from another program where the text is already coloured.