Monday, September 12, 2011

Word 2007 document with comments is crashing

My coworker had a document that had around 30 comments and when she'd click on the comment to delete it, Word 2007 would crash.  She mentioned that the comment targets somehow were erased and the comments were orphaned but still in the document.

Word has a recovery mode that did not work.  I tried copy/pasting to a new document which did not work.  Even tried using a VBA macro to delete a comment, then altered it to select and delete these other comments.  That didn't work either.

I know Word 2007 uses the new .docx format, which is really just a zip file container.  So I unzipped the .docx file, dug around in the supporting XML files, and found two files.  There is a document.xml and a comments.xml and inside the comments.xml file is an ID in each node that the document.xml file references.  Pretty simple layout.

In the document.xml file, I searched for "w:comment" and found hits on nodes named
<w:commentRangeStart w:id="3" />
<w:commentRangeEnd w:id="3"/>
<w:commentReference w:id="3"/>

Those nodes match the comments.xml document that has
<w:comment w:id="3">

Furthermore, while searching through the document.xml file, the IDs for problematic comments just happened to have

<w:commentReference w:id="3"/>
but not

<w:commentRangeStart w:id="3" />
<w:commentRangeEnd w:id="3"/>

So... Remove the broken references in document.xml and now there are fully orphaned items in comments.xml so remove those nodes as well.  Save all docs, then rezip the folder and rename to .docx

The doc opens fine, and Word 2007 no longer crashes :)  Woohoo.

No comments:

Post a Comment