Get a paragraph number/index from any paragraph with a document

S

Sardonic

I am currently writing a VBA routine to copy various pre-selected paragraphs
within document which are marked apart by tables and the start and end of a
section ie:

TABLE here
1st Para in section
2nd Para in section
3rd Para in section
Table here
1 Para in section
2 Para in section - and so on

I understand that paragraphs have an "index" number within a document. I
would like to know the "index" numbers of the starting/ending paras within a
grouping.
(eg paragraph(23) start, paragraph(25) end) This is so I can then copy those
paragraphs and pasting them to another document.

My imagined process to is navigate to the starting table then move down a
line - grab the paragraph's index value, then move to the next table and then
move up a line to grab the end paragraph's index value. But how do I grab
the paragraph's index number? Is there a simple Property I'm missing out on?
Paragraph.index ??
 
J

Jean-Guy Marcil

Sardonic said:
I am currently writing a VBA routine to copy various pre-selected paragraphs
within document which are marked apart by tables and the start and end of a
section ie:

TABLE here
1st Para in section
2nd Para in section
3rd Para in section
Table here
1 Para in section
2 Para in section - and so on

I understand that paragraphs have an "index" number within a document. I
would like to know the "index" numbers of the starting/ending paras within a
grouping.
(eg paragraph(23) start, paragraph(25) end) This is so I can then copy those
paragraphs and pasting them to another document.

My imagined process to is navigate to the starting table then move down a
line - grab the paragraph's index value, then move to the next table and then
move up a line to grab the end paragraph's index value. But how do I grab
the paragraph's index number? Is there a simple Property I'm missing out on?
Paragraph.index ??

You set a range from the start of the document to the end of the currently
selected range. Then you count the number of paragraphs
(Range.Paragraphs.Count) in that range, this will give you the index of the
last paragraph in the range.
This is how we do it fortables as well.
 
K

Klaus Linke

.... OTOH, using the paragraph indexes seems an unnecessarily cumbersome way
to get the range you want to copy.

It would probably be easier to just define a Range, and set its start and
end as you move through the tables (rngCopy.Start = para1.Range.Start,
rngCopy.End = para2.Range.End or something like that).

Regards,
Klaus
 
D

Doug Robbins - Word MVP

Use something like

Dim i As Long
Dim mrange As Range
With ActiveDocument
For i = 1 To .Tables.Count - 1
Set mrange = .Tables(i).Range
mrange.End = .Tables(i + 1).Range.Start
mrange.Start = .Tables(i).Range.End
'mrange now contains the paragraphs between each table
'If you want the first of those paragraphs, then use
mrange.Paragraphs(1).Range
Next i
End With


--
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
 

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