Revisions programming can be made to work??

J

John Wirt

I need a procedure that will print out all of the revisions in a document
along with their "parent" paragraph and sentence numbers. Here is the code
I've used (thx Helmut Weber for cmts):

For I = 1 To ActiveDocument.Paragraphs.Count
Set rngPara = ActiveDocument.Paragraphs(I).Range
For J = 1 To rngPara.Sentences.Count
Set rngSent = rngPara.Sentences(J)
Debug.Print "Paragraph " & Format(I, "00") & " Sentence " &
Format(J, "00") & " #Deletions= "; Str(cntDeletions) & " #Insertions= " &
Str(cntInsertions)
If rngSent.Revisions.Count > 0 Then
cntDeletions = 0
cntInsertions = 0
For Each Revn In rngSent.Revisions
If Revn.Type = wdRevisionDelete Then
cntDeletions = cntDeletions + 1
strRevnType = "Deletion:"
ElseIf Revn.Type = wdRevisionInsert Then
cntInsertions = cntInsertions + 1
strRevnType = "Insertion:"
End If
Debug.Print strRevnType; Revn.Range.Text
Next Revn
End If
Next J
Next I

The problem is that the revisions in the range rngSent.Revisions includes
_all_ of the revisions in the document rather than just the revisions in
pargraph, I, and sentence, J, as the code specifies should be the case.

Prior to iterating to the first paragraph _and_ sentence containing a
revision, the count of revisions rngSent.Revisions is 0, which is correct.
At the first _sentence_ containing a revisions, the count of revisions (and
the print out of revisions) jumps to all revisions in the document.

What is wrong here?

I am using the 9/2/2003 Word Patch, which contains repairs to Revisions (see
kb824936 thx ejlskov)

John Wirt
 
J

John Wirt

Let me give some additional symptoms.

1. The paragraphs and sentences can be printed out indvidiually with the
correct paragraph and sentence number (except for one problem to be listed
at the end). So the problem lies in the "ranging" of the revisions. They
are not limited to sentence J by the rngSent.Revisions structure.

2. While paragraphs and sentences can be printed out individually, the count
of insertions and deletions is the _same_ for all sentences in a paragraph
and equal to the total of all insertions and deletions in the document. The
torals jump to the totals for the document at the first sentence in the
document containing a revision.

3. The list of insertions and revisions that print out for the sentence also
includes _all_ of the insertions and deletions for the whole document.

4. In most cases, the list of all insertions/deletions prints out only for
(paragraphs and)sentences that contain an insertion or deletion. In most
cases, no insertions/deletions print out for the next sentence in the
paragraph. However, not alway!

Please note that the statements to reset the count of Insertions/Deletions
are in the wrong place in the code listed in my previous email. They should
be after the
If rngSent.Revisions.Count > 0 Then
cntDeletions = 0
cntInsertions = 0

So, the basic problem is that rngsent.Revisions statement, where Set =
rngPara.Sentences(J), does not restrict the revisions included to sentence
J.

John Wirt
 
H

Helmut Weber

Hi John,
what I see in your code is that you have omitted
the integer controlled loop, in which a new range is
set for each revision. According to my experience,
"for each" is not as reliable as "for i = 1 to x".
Of course, creating something at least partly new
is more rewarding than just copying and pasting.
The following code works perfectly in my environment:
Public Sub ExtractRevisions()
Dim i As Integer ' loop paragraphs
Dim j As Integer ' loop sentences
Dim k As Integer ' loop revisions
Dim sRst As String ' string result
Dim iPrg As Integer ' paragraphs count
Dim iSnt As Integer ' sentences count
Dim iRvs As Integer ' revisions count
Dim rPrg As Range ' range Paragraph
Dim rSnt As Range ' range sentence
Dim rRvs As Range ' range revision
Dim iDel As Integer ' count deletions
Dim iIns As Integer ' count insertions

iPrg = ActiveDocument.Paragraphs.Count
For i = 1 To iPrg
Set rPrg = ActiveDocument.Paragraphs(i).Range
iSnt = rPrg.Sentences.Count
For j = 1 To iSnt
Set rSnt = rPrg.Sentences(j)
iRvs = rSnt.Revisions.Count
iDel = 0
iIns = 0
For k = 1 To iRvs
Set rRvs = rSnt.Revisions(k).Range
sRst = "P(" & Format(i, "00") & ")"
sRst = sRst & " S(" & Format(j, "00") & ")"
sRst = sRst & " R(" & Format(k, "00") & ") "
If rSnt.Revisions(k).Type = wdRevisionDelete Then
iDel = iDel + 1
sRst = sRst & " D(" & Format(iDel, "00") & ") "
Debug.Print sRst & "[" & rRvs.Text & "]"
End If
If rSnt.Revisions(k).Type = wdRevisionInsert Then
iIns = iIns + 1
sRst = sRst & " I(" & Format(iIns, "00") & ") "
Debug.Print sRst & "[" & rRvs.Text & "]"
End If
Next k
Next j
Next i
End Sub
The result is:
P(10) S(04) R(01) I(01) [eeeeeee]
P(14) S(03) R(01) D(01) [capacitance ]
P(14) S(03) R(02) I(01) [ ]
P(14) S(04) R(01) D(01) [aluminum ]
P(14) S(05) R(01) D(01) [prevailing ]
P(14) S(05) R(02) I(01) [ ]
P(14) S(05) R(03) D(02) [electronics ]
P(14) S(05) R(04) I(02) [ ]
P(15) S(01) R(01) I(01) [eeeeeee]
P(15) S(05) R(01) I(01) [eeeeee]
P(15) S(05) R(02) I(02) [hhhhh ]
eg:
In paragraph 14, Sentence 5 there are 4 revisions,
of which 2 are Insertions and 2 are Deletions.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, W98
 
H

Helmut weber

....
"the debug.print" is better placed outside
the if commands. It should appear only once.
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, W98
 
J

John Wirt

Helmut,

Your revised code, where the For Each is replaced with a "For I=1 to"
iteration works substantially better than my last version of the code but
some strange things still happen.

Here is the text:I ran your code on:
___________
(p)
INDICATOR TEXT(p)
(p)
1. Apparently, the projections have changed since this indicator was last
published. Insert first sentence.[ Insert second sentence1.][ Insert third
sentence3.] I haven't been able to obtain a copy of the {new projections}
report so I cannot assess the impact of these changes on the conclusions
reported there and in our Condition of Education indicator.[ Play on2.]
[What is going on here4?](p)
(p)
Revised since previous estimates.(p)
(p)
Apparently, the projections have changed since this indicator was last
published. We need to footnote this in the volume.(p)
(p)
_____________
The "(p)s" are paragraph marks. The phrases between the []s are insertions
and the phrase between the {}s is a deletion. The numbers at the end of the
sentences denote the order in which the revisions were entered in the text.

Your code debug prints out this:

P(04) S(03) R(01) I(01) [Insert second sentence1.]
P(04) S(04) R(01) I(01) [Insert third sentence3. ]
P(04) S(05) R(01) D(01) [new projections5 ]
P(04) S(05) R(02) I(01) [ Play on2. What is going on here4?]
P(04) S(06) R(01) I(01) [Play on2. What is going on here4?]
P(04) S(07) R(01) I(01) [What is going on here4?]
P(05) S(01) R(01) I(01) [What is going on here4?]

There are some obvious problems in lines 5 through 8 of the print out. The
inserted sentence, "Play on.," is printed out twice, once as a change in
sentence 5 and again as a change in the new sentence 6. Furthermore, the
new sentence 6 also appears earlier as a change in sentence 4.

The deletion, "new projections," in setence 4 is listed as occurring in
sentence 5.

The inserted sentence, "Play on," is then listed as a change in sentence 5,
which is ccorect. "Playu on" is the new 5th sentence. The sentence, "What
is going on here?" is also listed as a change in sentence 5 and is then
repeated three more times in -- in sentences 6 and 7 of paragraph 4, and
then as sentence 1 of paragraph 5. Paragraph 5 doesn't really exist. At
least it has no sentences in it. It is just the blank line between
paragraphs 4 and 5.

This problem of the repetition of changes in sentences at the end of a
paragraph as changes in the first sentence of the following paragraph seems
to occur everytime a sentence is inserted as the new last sentence in a
paragraph. The change is reported as a change in the (new) last sentence and
then also as a change in the first sentence in the following (blank line)
paragraph . I have tried various strategems to stop this problem but
nothing I have tried works..

What is going on here? This is very strange behavior.

John Wirt

Helmut Weber said:
....
 
J

John Wirt

Sorry, another mistake. In what I have just submitted, the sentence,

"Furthermore, the new sentence 6 also appears earlier as a change in
sentence 4."

should instead be,

"Furthermore, the new sentence 6 also appears earlier as a change in
sentence 5."

John Wirt
 
H

Helmut Weber

Hi John,
I'm sorry to say so, but it seems there is a limitation
as to what amount of complexity can be handeled with
justifiable effort. There may be insertions,
revision of insertions resulting in partially deletion
of former insertions, moved paragraphs, undone moving of
paragraphs and so on. In the end, it would result in
recording every keystroke of one or more editing sessions.
Must be possible, though, but would be equal to
a movie showing somebody typing.
I'm at the end of wisdom.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
 
J

John Wirt

Thank you for your assitance. I will let you know how I come out.

i apologize for posting to the German Word.vba news group. Acutally, I meant
the posting as a complement. Posting in foreign language to a U.S. English
newsgroup would be fruitless. Few here are conversnt in a foreign language.

My impression is that Europe is different. Many (most?) Europeans know a
foreign language and many know English. So I thought someone might be able
to respond who wouldn't see the U.S. Word VBA news group.

Anyway, I apologize for intruding.

John Wirt
 

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