Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2007

Tip: Looking for answers? Try searching our database.

Macro Speed for large indexes of ActiveDocument.Paragraphs

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SirCodesALot - 30 Oct 2007 21:13 GMT
Hi,

I have a macro that is doing some indenting.  Depending on the
previous paragraphs text, I may or may not have to indent all that
paragraphs children.

The problem am having is that my document has about 5000 paragraphs,
and as my index into the ActiveDocument.Paragraphs(Index) gets above
about 300, this really start slowing down... any one know why?

Here is an example of the code:

AllParagraphs = ActiveDocument.Paragraphs.Count

For i = 1 To AllParagraphs

          If (ActiveDocument.Paragraphs(i).Style = sReqStyle) Then

                For j = i + 1 To AllParagraphs
                       If (ActiveDocument.Paragraphs(j).Style =
sReqStyle) Then
                                 If (IsSubRequirement(i, j)) Then
                                    ' indent
                                     j = IndentRequirement(i, j) - 1
                                 End If
                        End If
                Next
         End If
 Next

As i gets above about 300, it really shows down.  Is their a better
way to do this?
I have already tried turning of page updating.

thanks for your help,
-SJ
Tony Jollans - 30 Oct 2007 21:41 GMT
When youi reference a paragraph using ...

   (Container).Paragraphs(i)

Word has to start at the beginning and count through the paragraphs until it
gets to the i'th one. The higher i, the longer it takes.

What you are doing *is* a lot of work (checking 25 million paragraphs) and I
don't know enough of your circumstances to suggest how you might reduce that
amount but you may find it a little better if you change the way of
referencing the paragraphs ...

   For Each Pi in ActiveDocument.Paragraphs
       If Pi.Range.End < ActiveDocument.Range.End Then
           For Each Pj In ActiveDocument.Range(Pi.Range.End,
ActiveDocument.Range.End).Paragraphs
               ' Do your stuff ...
           Next Pj
       End If
   Next Pi

(untested)

Signature

Enjoy,
Tony

> Hi,
>
[quoted text clipped - 32 lines]
> thanks for your help,
> -SJ
SirCodesALot - 31 Oct 2007 16:22 GMT
On Oct 30, 3:41 pm, "Tony Jollans" <My forename at my surname dot com>
wrote:
> When youi reference a paragraph using ...
>
[quoted text clipped - 61 lines]
>
> - Show quoted text -

Tony,

Thank you for your response, I didnt know that it did that. I
appreciate you example and that should help me speed it up, i will
give it a shot!

thanks again,
-SJ

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.