Revision.Type property - inconsistent results

M

Mark Tangard

I’m trying to add code to a macro to make it behave differently if the text it
works on has tracked changes, but Word seems to act on whim rather than reality.
Has anyone else tried to use [range_object].Revision(1).Type and gotten
inconsistent or apparently wrong results?

For example, in some documents I want the macro to add characters to a certain
word, but only if the word isn't within a tracked deletions, since that makes
the added characters UN-tracked (undeleted), so when revisions are accepted the
added characters remain while what’s around it is erased. I would have thought
code like this:

If Selection.Range.Revisions(1).Type = wdRevisionDelete Then [etc]

.....where the Selection is only 1 word and definitely contains only 1 revision,
would allow the code to evaluate accordingly and consistently (and in this case,
skip the action that would be performed if the Selection had no tracking).

But very often it behaves as if this line of code isn’t there, and the action
after that line *is* performed, with unmanageable results.

Testing with MsgBox Selection.Range.Revisions(1).Type seems to return equally
baffling results -- often it returns the value of 1 for an insertion *or* a
deletions.

Am I using the wrong constant? I don’t see one that would mean the same thing.

Any help appreciated.
 
D

Doug Robbins - Word MVP

Hi Mark,

In a test just performed on a document with many revisions, using the
following code:

Dim arev As Revision
For Each arev In ActiveDocument.Revisions
arev.Range.Select
MsgBox arev.Type
Next arev
End Sub

consistently returns 1 for an insertion and 2 for a deletion (3 for a
formatting change)

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

Jezebel

Do you have an 'on error resume next' lurking about? An unexpected
side-effect is that if an If statement throws an error, VBA acts as if the
statement returned true (ie it resumes at the next line, literally).
 
S

Shauna Kelly

Hi Mark

A year or so ago I tried to understand all the possible permutations of
tracked changes and what .Revision(1).Type returns. The short story is that
I gave up on the idea of using it for consistent results.

It seems to be OK if the tracked change is nothing more than an insertion or
deletion of text. But if the insertion or deletion had any side effects (eg
causing a numbered paragraph further down the document to re-number), or if
fields are updated (eg a SEQ field), or if Word decides that the change
resulted in a formatting change), then all bets are off.

As an example, updating a SEQ field such that the number changes results in
a wdRevisionDelete and a wdRevisionInsert. But updating other fields (eg a
Page field) shows no revision at all.

Or, if you insert a column in a table, it's shown as a
wdRevisionTableProperty, but if you insert a row, it's a wdRevisionInsert.

Word reports info about a revision in (at least) 5 places: text in a
balloon, in the menu at a right-click on the change, in the old "Accept or
Reject Changes" dialog, in the Revision(1).Type and in the
Revision(1).FormatDescription. I don't think you'd be astonished to discover
that there are inconsitencies between the 5. As an example, if you insert a
paragraph to which a numbered style is applied, thus causing subsequent
paragraphs in that style to renumber, a balloon shows no change, but a
right-click shows a Format Change.

Some of the Revision Types never appear to be used. I could never find an
example of a wdRevisionStyle, wdRevisionStyleDefinition,
wdRevisionDisplayField, wdRevisionConflict or wdRevisionReconcile (though I
suspect the last two might be used by Compare and Merge, and my experiments
didn't go that far).

As a final curiosity, try this. Create a new document and type one word into
it. Turn on Track Changes. Show Final Showing Markup, using Balloons.
Without moving the cursor (which is at the end of your first word), do
ctrl-b (for bold) and type another word. ActiveDocument.Revisions.Count
returns 1, and the type is wdRevisionInsert. But the UI sees this as two
revisions, and allows the user to accept or reject the insertion separately
from the bolding. So, click at the beginning of word 1, then use the Next
button on the Reviewing Toolbar, and then click the Accept Change button. I
still see the balloon for "Formatted: Font: Bold", and in the UI I can
accept or reject that change. But ActiveDocument.Revisions.Count returns 0.

As far as I can see, that revision, observable in the document, is not
accessible from the object model. And this suggests that the Revisions
collection exposed to the object model is not the same thing that the UI
uses to determine what to display, move to, and accept or reject.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word


Mark Tangard said:
I’m trying to add code to a macro to make it behave differently if the
text it works on has tracked changes, but Word seems to act on whim rather
than reality. Has anyone else tried to use [range_object].Revision(1).Type
and gotten inconsistent or apparently wrong results?

For example, in some documents I want the macro to add characters to a
certain word, but only if the word isn't within a tracked deletions, since
that makes the added characters UN-tracked (undeleted), so when revisions
are accepted the added characters remain while what’s around it is erased.
I would have thought code like this:

If Selection.Range.Revisions(1).Type = wdRevisionDelete Then [etc]

....where the Selection is only 1 word and definitely contains only 1
revision, would allow the code to evaluate accordingly and consistently
(and in this case, skip the action that would be performed if the
Selection had no tracking).

But very often it behaves as if this line of code isn’t there, and the
action after that line *is* performed, with unmanageable results.

Testing with MsgBox Selection.Range.Revisions(1).Type seems to return
equally baffling results -- often it returns the value of 1 for an
insertion *or* a deletions.

Am I using the wrong constant? I don’t see one that would mean the same
thing.

Any help appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top