Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 22 of 22

Thread: Strange behaviour of Word VBA

  1. #21
    VBAX Regular
    Joined
    Jun 2011
    Posts
    30
    Location
    Some of the problems seem to be due to the complexity of the document. My 480 page, 20000 paragraph test document had over 4000 bookmarks most of which were dormant, and 700 REF fields. Converting the fields to text and removing unused bookmarks gave a big improvement to the timing. With the TOC visible the timing came down from 30 minutes to 2 minutes. If the TOC is not visible then the timing came down from 80 to 28 seconds.

    Therefore:

    The timing is dependent of a whole heap of factors, not just the number of paragraphs. The visibility of the TOC is just one of them.

    For large documents, if the screen is displaying a TOC it is well worth jumping to another page before executing the For Each… code.

  2. #22
    VBAX Regular
    Joined
    Jun 2011
    Posts
    30
    Location
    More curious timings.

    Sub timings()
    Dim tm As Single
        tm = Timer
        MsgBox ActiveDocument.Paragraphs.Count & "   time=" & Timer - tm
    End Sub
    20 seconds on 480 page test doc
    1.9 seconds on same document with REF fields converted to text

    Sub timings()
    Dim tm As Single
        tm = Timer
        MsgBox ActiveDocument.Sentences.Count & "   time=" & Timer - tm
    End Sub
    1.7 seconds on test doc
    3.3 seconds on same document with REF fields converted to text

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •