It is not surprising that it crashed, as you didn't do what I said. The sub and the two functions I posted are ALL that you need. You appear to have at least two macros trying to do similar things without closing the document, so you are trying to save the document with a document already created by another version of the code, which is still open.
I have added code to close the document so that if you run it twice it won't crash. See attached.