Skip to main content

Accessing Subversion Keywords from MS Word

Tobi Oetiker, 2011-11-23

The Issue

SVN Keywords help me a lot in keeping my documents in order. Thanks to keywords I always know which version of the file I am looking at, when it was last modified and by whom. For text files, keywords are very simple to use. For binary file formats like the stuff you get with windows programs this does unfortunately not work. Binary keyword substitution may provide a way out of this problem, but only for the most simple of binary file formats. TortoiseSVN (> version 1.5) provides a way out of this problem. It can be acessed as a com component from within any windows application that provides the necessary interface.

The TortoiseSVN COM Component

If you are using SVN from windows, you will most likely have TortoiseSVN installed. Starting with version 1.5 (or a current svn snapshot, as long as 1.5 is not released) provides an COM interface to read SVN keyword properties from within any language capable of accessing COM components. In Visual Basic for Applications this would look something like this:

Dim oSvn As Object
Set oSvn = CreateObject("SubWCRev.object.1")
oSvn.GetWCInfo ActiveDocument.FullName, 1, 1
Debug.Print "Revision: " & oSvn.Revision

The ActiveDocument.FullName function returns the name of the current document in MS Word.

MS Word Integration

I wrote a VBA Word macro that stores the SVN keyword information into the Word document properties whenever the document is loaded, or a new document is created based on a template containing the macro.

The special property 'svnWarning' will show information about the current state of affairs. It will contain a warning when Tortoise is not installed or when the document is not under SVN control.

Installation

  1. Download the macro.
  2. Add the macros to a document or if you want them active all the time, add them to your favorite template/dot file.
    [Extras] -> [Macros] -> [Visual Basic Editor]
    [Import]
    
  3. Use the svn properties from the Insert Field dialog.
    [Insert] -> [Field] -> [DocProperties]
    

Legacy Support

An earlier version of the script exists, which works with SVN fixed-length keywords. Note that this will only work with classic DOC file; it will break with Office 2007 XML files.

 

Sorry

It seems JavaScript has been disabled in your browser. This site, like most of the Internet contents these days, does not work properly without JavaScript. Please re-enable JavaScript, or use a different Browser.


If you need help fixing your browser, please send mail to support@oetiker.ch