This article explains how to insert code in Word. The instructions apply to Word 2010 and later, including Word 2021 and Microsoft 365.
While there is no "insert code" option or special code block in Word, there is a way to insert one document into another. This effectively creates an isolated section that houses all of the code. Here's how to make this work with your code:
Open the document in which you want to display the code and select Insert.
Select Object in the Text group.