We’re thinking about putting some of our Microsoft Word documents under source control in our Team Foundation Server. It would be great to be able to compare MS Word documents in the same way we compare source code.
The Team Foundation Server client can be configured to use any executable to compare or merge two files. In Visual Studio 2005, for example, go to Tools / Options then select the Source Control section. On the Visual Studio Team Foundation Server panel press the “Configure User Tools…” In the Configure User Tools dialog you can associate different file extensions with any comparison or merge tools you want.
For instance I changed my default comparison tool to KDiff3 by associating .* with the KDiff3.exe file. Then for comparisons I set the command line to:
%1 --fname %6 %2 --fname %7
and for merge:
%3 --fname %8 %2 --fname %7 %1 --fname %6 -o %4
Now KDiff3 does a great job with code, but comparing MS Word documents is not its forte! Looking around online, many people recommend Diff Doc. I hooked it up and it worked pretty well… but I wasn’t quite satisfied. Microsoft Word 2007 can compare two documents… surely it can do the comparison for me?
Looking at the command-line switches for Word 2007 there isn’t one that instructs it to compare two files, but there is one that allows you to run a macro… and comparing two documents is possible from a macro!
So I recorded a macro to compare two documents, then adapted it for my purposes. Here is an early version that probably needs more work:
RevisedDocument:=Documents(2), Destination:= _
wdCompareDestinationNew, Granularity:=wdGranularityWordLevel, _
CompareFormatting:=True, CompareCaseChanges:=True, CompareWhitespace:= _
True, CompareTables:=True, CompareHeaders:=True, CompareFootnotes:=True, _
CompareTextboxes:=True, CompareFields:=True, CompareComments:=True, _
CompareMoves:=True, RevisedAuthor:="Author", IgnoreAllComparisonWarnings _
ActiveWindow.ShowSourceDocuments = wdShowSourceDocumentsNone
This macro compares the first two open documents it finds, initialising some comparison settings. This will create a new document containing the track changes between the two source documents. It then closes the two source documents.
If this macro is saved into your normal.dot template, it can then be called by the TFS client. Associate WinWord.exe with .doc and .docx then set the command line to:
/mCompareDocuments /n /q %2 %1
/mCompareDocuments calls the above macro. %2 %1 pass the document filenames. /n starts a new instance of MS Word, which should mean only the two documents to be compared are available in the Documents collection (I couldn’t find a way for the macro to directly use the filenames passed on the command line). /q suppresses the splash screen.
Give it a go… record your own macro to try different settings.