This hack shows you how to edit the information Word stores when you edit a document using the Track Changes feature.
In addition to marking revisions in a document, Word's Track Changes feature remembers who made the revisions. It lets you view up to eight different revision authors in a single document, each of whose changes are displayed in a different color.
|
But what if you want to modify the name of the author of a particular set of revisions? For example, say you took some work home for the weekend and accidentally did your editing while logged into your computer as one of your kids. Now all your revisions appear as though your teenage son made the changes. Many coworkers would be forgiving, but a client would hardly look kindly on this error.
Unfortunately, you can't modify a revision author from VBA. It does have a Revision object with an Author property, but the property is read-only, meaning you can't give it a different value.
To make the change, you'll need to get the document into a format that takes it out of Word's control, such as RTF (Rich Text Format). When you save a document as an RTF file, you retain the revision information. You can then edit the RTF file with any standard text editor, such as Notepad.
Here's how to change the author of a set of revisions in a Word file.
First, select File
|
To locate the part of the file that contains the names of the revision authors, do a search in the file for the following:
{\*\revtbl
You will see a list of revision authors following the string characters, as shown in Figure 4-22. The first entry in the list is always Unknown, which you should leave as is. If you edit any of the other names in the list, all revisions attributed to that name will show the change when you open the document in Word.
After you make the change to the RTF file, save it, and then open it
in Word. You can now select File
|
Editing RTF files by hand is tricky business. If you regularly swap revision authors in a document, a Perl script can take over the dirty work.
|
The following script requires the RTF::Tokenizer module. If you use the ActiveState distribution of Perl, you can use the Perl Package Manager, available from the ActivePerl entry on your Start menu, to install RTF::Tokenizer.
#!/usr/bin/perl use strict; use Getopt::Long; use RTF::Tokenizer; my %opts = ( ); GetOptions (\%opts, 'from=s', 'to=s'); my $filename = shift; die "Please provide an rtf file to parse.\n" unless $filename; my $tokenizer = RTF::Tokenizer->new( file => $filename); while( my ( $type, $arg, $param ) = $tokenizer->get_token( ) ){ last if $type eq 'eof'; if($type eq 'control' and $arg eq 'revtbl') { my $match = 0; put($type, $arg, $param) if $opts{from} and $opts{to}; my $brace = 1; while($brace > 0){ my @attr = $tokenizer->get_token( ); $brace++ if $attr[0] eq 'group' and $attr[1] == 1; $brace-- if $attr[0] eq 'group' and $attr[1] == 0; if( $attr[0] eq 'text') { $attr[1] =~ s/;$//; if( $opts{from} and $opts{to} ){ if( $opts{from} eq $attr[1] ) { $attr[1] = $opts{to}; $match = 1; } $attr[1] .= ';'; put( @attr); } else { print $attr[1], "\n" unless $attr[1] eq 'Unknown'; } } else { put(@attr) if $opts{from} and $opts{to}; } } if($opts{from} and $opts{to} and !$match) { print STDERR "The author $opts{from} was not found in the document!\n"; } } else { put($type, $arg, $param) if $opts{from} and $opts{to}; } } sub put { my ($type, $arg, $param) = @_; if( $type eq 'group' ) { print $arg == 1 ? '{' : '}'; } elsif( $type eq 'control' ) { print "\\$arg$param"; } elsif( $type eq 'text' ) { print "\n$arg"; } }
Save the script as "authorswap.pl" and put it in the same folder as the RTF file. Run it at a DOS prompt without any arguments to get a list of the revision authors in the document, as shown below:
> perl authorswap.pl MyDoc.rtf > Brett Johnson Rael Dornfest
To replace one revision author with another, use the to and from options, as shown below. Place the names inside quotation marks.
> perl authorswap.pl -from "Brett Johnson" -to "Bob Smith" MyDoc.rtf > NewFile.rtf
The file NewFile.rtf will reflect the changes.
Andrew Savikas and Andy Bruno