Use the Insert Object feature to create a separate document for your code in Word. You can paste special to keep your code's format when putting it into Word. This article explains how to insert code in Word. Directions apply to Word 2010 and newer, including Word 2021 and Microsoft 365.