Return index of paragraph?

E

Ed

A macro iterates through all the paragraphs of a range. I'd like to put a
message in the status bar to tell me which paragraph the macro is currently
working on. How do I return the index number of the paragraph?

Ed

For Each par In rng.Paragraphs
If Not par.Range.Information(wdWithInTable) Then
If par.Format.Alignment <> wdAlignParagraphCenter Then
Application.StatusBar = "Now on Para. No. " & ***Paragraph.Index***
& " of " & rng.Paragraphs.Count
 
J

Jonathan West

Ed said:
A macro iterates through all the paragraphs of a range. I'd like to put a
message in the status bar to tell me which paragraph the macro is currently
working on. How do I return the index number of the paragraph?

Ed

For Each par In rng.Paragraphs
If Not par.Range.Information(wdWithInTable) Then
If par.Format.Alignment <> wdAlignParagraphCenter Then
Application.StatusBar = "Now on Para. No. " & ***Paragraph.Index***
& " of " & rng.Paragraphs.Count

Do this


iCount = 0
iTotal = rng.Paragraphs.Count
For Each par In rng.Paragraphs
iCount = iCount + 1
If Not par.Range.Information(wdWithInTable) Then
If par.Format.Alignment <> wdAlignParagraphCenter Then
Application.StatusBar = "Now on Para. No. " & CStr(iCount) _
& " of " & CStr(iTotal)



--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jean-Guy Marcil

Ed was telling us:
Ed nous racontait que :
A macro iterates through all the paragraphs of a range. I'd like to
put a message in the status bar to tell me which paragraph the macro
is currently working on. How do I return the index number of the
paragraph?
Ed

For Each par In rng.Paragraphs
If Not par.Range.Information(wdWithInTable) Then
If par.Format.Alignment <> wdAlignParagraphCenter Then
Application.StatusBar = "Now on Para. No. " &
***Paragraph.Index*** & " of " & range.Paragraphs.Count

Do you mean the index of the paragraph in the range or the absolute index of
the paragraph in the document?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jay Freedman

Hi Ed,

You can use a variation on the technique in the second part of
http://www.word.mvps.org/FAQs/MacrosVBA/GetIndexNoOfPara.htm, but I think it
would be faster to just keep an incrementing counter:

Dim nPar As Long
For Each par In rng.Paragraphs
nPar = nPar + 1
If Not par.Range.Information(wdWithInTable) Then
If par.Format.Alignment <> wdAlignParagraphCenter Then
Application.StatusBar = "Now on Para. No. " & nPar & " of " &
rng.Paragraphs.Count

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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