Identifying the "parent" sentence and paragraph of revisions

J

jwirt

I would like to write a VBA procedure to extract all the revision marked
text from a document and list it in a file alongwith the paragraph and
sentence number of the sentence in which the revision marked text is
located.

How can I identify the parent paragraph and sentence of each object in
the revisions collectoin of a document?

John Wirt
 
C

Cindy M -WordMVP-

Hi Jwirt,
I would like to write a VBA procedure to extract all the revision marked
text from a document and list it in a file alongwith the paragraph and
sentence number of the sentence in which the revision marked text is
located.

How can I identify the parent paragraph and sentence of each object in
the revisions collectoin of a document?
the paragraph part is easy enough. Roughly:
ActiveDocument.Revisions(index).Range.Paragraphs(1).Range.Text

But a sentence number... Are you talking about numbering the sentences
from the beginning of the document? Or within the paragraph? Are you using
any numbering that you want to reference?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
J

jwirt

By sentence number, I mean sentence number within the paragraph.

I've written this code;

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 "P" & Format(I, "00") & " S" & Format(J, "00")
____Debug.Print rngSent.Text
____If rngSent.Revisions.Count > 0 Then
_______< code to be placed here for printing revisions>
____End If
__Next J
Next I

This code works except if the "paragraph" is actually a header with n
period at the end and the next line is a blank, the routine reprint
"sentence" (header) from the first line. I have tried various things t
set the "sentence" for the 2nd paragraph to blank ("") but nothin
works.

1st try: Add Set rngSent = Nothing before Set rngSent
rngPara.Sentences(J).

2nd try: Test the length of the sentence and if it is zero, force th
sentence to blank. This failed because the length is always the sam
as the header in the previous (nonblank) line. Apparently, Word VB
does not reset the rngSent when a new paragraph is encountered. Eve
setting it to Nothing doesn't work.

Odd (or so it seems to me).

John Wir
 
C

Cindy M -WordMVP-

Hi Jwirt,
This code works except if the "paragraph" is actually a header with no
period at the end and the next line is a blank, the routine reprints
"sentence" (header) from the first line. I have tried various things to
set the "sentence" for the 2nd paragraph to blank ("") but nothing
works.
Well, empty paragraphs in a document are "politically incorrect". You
should be using SpaceBefore or SpaceAfter formatting to generate space
between paragraphs. Ideally.

For I = 1 To ActiveDocument.Paragraphs.Count
__Set rngPara = ActiveDocument.Paragraphs(I).Range
If Len(rngPara.Text) <=1 Then 'contains only a paragraph mark/is empty

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
J

John Wirt

Cindy, thanks. Between you and Helmut Weber I think Germany is the only place where good VBA programming is being done -- on revisions anyway.

In your reply,
Well, empty paragraphs in a document are "politically incorrect". You
should be using SpaceBefore or SpaceAfter formatting to generate space
between paragraphs. Ideally.

What do you mean by using SpaceAfter and SpaceBefore formatting.?

In writing a document, I often manually include headings at various levels to block and organize the text for making it easier to read. I don this by simply enter the heading (typing it in) and then entering a carriage return.

These one line, non sentence, "paragraphs" of text certainly do mess up Word's tracking of revisions. My recent posts in microsoft.word.vba.general describe the problem. Revision Tracking in VBA seems to repeat any revisions in a paragraph/sentence prior to one of these manual headings (it's really a "blank," one line paragraph with no sentence becasue there is no period) until it encounters a real paragraph with real sentences in it.

Your recommendation is to simply test the paragraph length and skip it if the length is zero? I think I've tried this but I'll try it again.

I think the problem will be this. Suppose the text is:

Para 6, Sentence 5: some text.
Para 7, blank line
Para 8, manual heading
Para 9, blank line
Para 10, sentence 1: some text.

Without the zero length filter, any revisions in Para 6, Sentence 5 will also appear in a range restrict to Para 7, Para 8, and Para 9. With the line length limit, I think they will still appear in Para 8, since of course it is not zero length.

I suppose I could also test for the presence of a period and skip "sentences" that are, in fact, not sentences.

My fear is that going down this track is going to lead to some very fragile and unpredicatable code. As code for extracting revisions from a document it won't be very robust. My basic question is why is revision tracking in VBA so "unpredictable," is what I woudl call it, and is there any other approach you would recommend, possibly using more sophisticated VBA concepts ? What I'm doing now is simply using three nested For i=1 to count loops to cycle through all the paragraphs, then sentence, then revisions. The code works fine at the paragraph and sentence levels but falls down on the "zero length" paragraphs.

Thanks

John wirt
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?Sm9obiBXaXJ0?=,
In your reply,

What do you mean by using SpaceAfter and SpaceBefore formatting.?
Go to the Format/Paragraph dialog box and look for Space Before and Space
After. You can enter values here that will separate this paragraph from
preceding, resp. following text. Without having to press ENTER additional
times. Using this technique will make automated processing of documents
MUCH easier.

Since it's "a pain" to have to always go into dialog boxes for particular
formatting, it makes a lot of sense to use a paragraph STYLE to apply
document structure specific formatting. (And styles also help a lot when
automating a document)

To make end user's lives a bit easier, Word comes with predefined Heading
styles. If you don't like the formatting, you can modify the style
definition. (I'd need to know the version of Word to tell you exactly where
to do this)

And in order to re-use this easily for multiple documents, create a
TEMPLATE and use that when you need to write a new document of a particular
type.

This is how Word was designed to be used, so the other features (such as
revisions) will only work optimally when a document was constructed in this
manner.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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