Extracting Revisions by paragraph and sentence

J

John Wirt

The following procedure is suppose to extract the revisions in a document by
paragraph and sentence within each pragraph:

**************************
Public Sub ExtractRevisions()
Dim Revn As Revision
Dim colRevns As Revisions
Dim rngRevns As Range
Dim Para As Paragraph
Dim colParas As Paragraphs
Dim rngPara As Range
Dim colSents As Sentences
Dim rngSent As Range

cntParas = ActiveDocument.Paragraphs.Count

For I = 1 To cntParas
Set colSents = ActiveDocument.Paragraphs(I).Range.Sentences
For J = 1 To colSents.Count
Set colRevns = colSents(J).Revisions
If colRevns Is Nothing Then GoTo NextJ
For Each Revn In colRevns
Debug.Print "Para" & Str(I) & " Sent" & Str(J) & " Rev:" &
Revn.Range.Text
Next Revn
NextJ:
Next J
Next I

End Sub
****************************

The program compiles but all revisions are printed out for each paragraph
and sentence within each paragraph. In other words, all revisions in the
whole document are printed out for Para 1 and sentence 1, para 1 and
sentence 2,...para8 and
sentence 1, and so forth. The same revisions for all paragraphs and
sentences.

The paragraphs and sentences print out correctly (there are only as many
sentences within
each paragraph as there are sentences within each paragraph. It's just that
all revisions are attached to each paragraph and sentence, when in a test
run there were only two revisions in one of the sentences in one of the
paragraphs. The number of paragraphs and sentences that print out is
correcct.

ANy help will be greatly appreciated.

John Wirt
 
H

Helmut Weber

Hi John,
forgive me for saying so, but your code seems
a bit messy. So I didn't debug it, but created this,
which may be clearer. The square brackets [] are
there to visualize, whether blanks are revisions, too.
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

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
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") & ") "
Debug.Print sRst & "[" & rRvs.text & "]"
Next
Next j
Next i
End Sub
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, W98
 
J

John Wirt

Helmut,

Thank you very much. Not many are apparently into coding the revision
marking capabilities of Word. I'll take your message about placing clean
code on this forum to heart. Cleaner code would make it easier for people to
respond. I hadn't thought of that before.

John
 
H

Helmut Weber

Hi John,
did it work?
from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
 
J

John Wirt

Helmut,

Yes, it worked! Thank you again.

The next step is to distinguish between deletions and additions in printing
out the revisions. I'll upload some code tonight.

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