Tracking the number of the paragraph as I cycle through a document

D

DannyE

Hi Guys,

I am going to be running a process to check for duplicates at
paragraph level in a number of files so I am going to try to do i
programaticly.

First of all the code I envisage will be a for each paragraph i
paragraphs which will loop me through all the paragraphs easily, but
need to keep a track of the number of the paragraph in the collectio
so that I don't check previously tested paragraphs. Also if I remove
paragraph from the collection I think I am right in saying that tha
will cause the collection to reset so I would have to then star
checking from the beginning again?

I have looked into the selection.information but it doesn't seem t
give me what I need so I am expecting to have to maintain an inde
which will refer to the current paragraph which is to be checke
against and then another index of the following paragraphs to incremen
as each onme is tested against the current paragraph? I have also trie
to fish my way through the locals window to see if I can find
reference in there but without sucess so far...

I'm not looking for code or anything, just your thoughts on how I coul
do this...

Many thanks for your time,

Best regards,

Da
 
H

Helmut Weber

Hi Danny,

Sub Makro6()
Dim prg1 As Paragraph
Dim prg2 As Paragraph
For Each prg1 In ActiveDocument.Range.Paragraphs
For Each prg2 In ActiveDocument.Range.Paragraphs
If prg1.Range.text = prg2.Range.text Then
If prg1.Range.start <> prg2.Range.start Then
prg2.Range.Delete
End If
End If
Next
Next
End Sub
I'm not looking for code or anything,
just your thoughts on how I could
do this...

Instead of comparing each paragraph with
each *other* paragraph
you could compare each paragraph with each paragraph
check whether they hold the same text,
*and* check, whether they occur at the same position,
that is, whether they are identical in the sense of logic.

http://en.wikipedia.org/wiki/Identity_(object-oriented_programming)

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
D

DannyE

Hi Helmut,

I like you idea, seems very economical in coding terms :)

Many thanks for your help.

Best regards,

Da
 
D

DannyE

Thanks again Helmut,

All works fine and only takes a matter of a few seconds even ove
several pages of paragraphs.

Best regards,

Da
 

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