Subversion’s “keyword” feature is great to automatically tag text files with the revision number. I’d really like to do a similar thing for Word and/or OpenOffice documents.
I tried this with Word documents, by inserting a “fixed-width” keyword substitution into the “comment” document properties field. But it seemed to still corrupt the document somehow (plus I don’t know what “fixed-width” might mean in the case of multi-byte characters). I also didn’t like this idea because it would not be good for inserting the number in the printable part of the document itself.
What I’m imagining now is a macro that automatically runs on document open, and updates a custom document property. The document could contain doc property reference fields that get updated with the value stored in the doc property.
Has anyone done this, or done anything else to achieve this goal? For either Word or OpenOffice?
First: Embedded Version Numbers – Good or Evil?: I find them evil.
You should not use technical internal revision number to represent the version of a document.
“This is the 2.2 revision of my word document” is not the same than “this is revision 1567 of my word document”.
Plus, if it modifies the document with the current revision number, it still need to be committed, meaning the stored version would be in a revision number different than the one updated by your macro.
If not committed, there is always the chance that the document being tagged like that is not exactly the one initially queried from Subversion.
That being said… on the more general issue of updating Office document properties:
That thread update word 2003 fields automatically suggests the use of an Office API. Microsoft.Office.Interop does not allow property modification, but the VBA API does allow you to access any CustomProperty you want to set for a given SmartTag.
This article “To add a smart tag with a custom recognizer to a Word document” gives you an example of a SmartTag custom behavior.
Smart tags are strings of text that have type information attached to them; when a text string that matches the criteria appears in a document, it is recognized and the user is able to perform actions appropriate for that type of string.
So one could imagine a SmartTag able to recognize the string “revision for this document”, with the custom behavior being “I will query the right revision number to SVN and display it”