PDA

View Full Version : XML corruption with "track changes" Word 2003



falconwing
08-12-2008, 02:06 PM
I wrote a VBA project that has been working fine for my users for several months now. They fire up the macro and use the userforms to add, modify, and delete XML structures embedded in the document.

Recently I had a user come to me with problems running the macro. I looked at the XML Structure task pane and sure enough the structure was corrupted.

When I looked at the document I saw the active part of the document had valid XML. However, what surprised me was that the deleted XML also was showing up in the XML structure in the Task Pane! What was different in this case was the user had turned on "Track Changes".

I allowed word to save the document as XML "even if not valid" so I could look at the raw wordml. This properly showed the XML data as deleted and inserted. What was interesting was when I looked at the "save data only", which eliminated anything my code was doing. The "save data only" data looked like the XML structure Task Pane, and like the data my macro was retrieving by walking the xml nodes - the deleted XML was sitting there!

Good example (deletes disappear):
<Reqt>
<Review_Status>...</Review_Status>
</Reqt>

Bad example:
<Reqt> [deleted]
<Review_Status>...</Review_Status> [deleted]
<Reqt>
<Review_Status>...</Review_Status>
</Reqt>
</Reqt> [deleted]


Based on this behavior, I assume this is a bug in Word. Other than turning track changes off when the macro runs, I've not seen any easy way around this problem. Any ideas out there?

Thanks,
FalconWing

macropod
08-13-2008, 04:33 AM
Hi FalconWing,

In addition to turning track changes off when the macro runs, you might also programmatically ensure all tracked changes are accepted. Here's some code to play with:
Sub Main()
Dim TrkStatus As Boolean ' Track Changes flag
' Turn Off Screen Updating
Application.ScreenUpdating = False
' Store current Track Changes status, then switch off
With ActiveDocument
TrkStatus = .TrackRevisions
.TrackRevisions = False
.Revisions.AcceptAll
' Call your XML-processing code here
'
' Restore original Track Changes status
.TrackRevisions = TrkStatus
End With
' Restore Screen Updating
Application.ScreenUpdating = True
End Sub

falconwing
08-13-2008, 04:52 AM
Macro,
Thanks for the response. I thought perhaps this bug was fixed in Word 2007 but now our IT group no longer supports anything other than Word 2003.
FalconWing

macropod
08-13-2008, 05:07 AM
Hi FalconWing,

Since Word 2007's native file format is XML and change-tracking is implemented within that, I'm not sure you could call it a bug.

FWIW, if you download the Word 2007 filters that MS has produced for Word 2000 - Word 2003, you can use Word 2003 to save the files in the new docx (ie zipped XML) format.

falconwing
08-13-2008, 05:36 AM
The wordML with track changes looks correct to me, and it displays the text correctly. However, Word does not treat deleted XML any differently in track changes mode so you get it all when you walk through the XML nodes, look at the XML Structure in the Task Pane, and you get it all when you "save data only", so I call that a bug. :content: