Can you describe a bit better the problems you're running into?
Generally, if I'm bringing code into a document
- I make sure I write only short lines in the code editor, with continuation marks (space underline at the end of a line with a "half-indent" on the continuing lines)
- I format it with a "code" paragraph style in which spell check is deactivated, usually with a non-proportional font (such as Courier)