Looping a Word macro over many list paragraphs causes memory issue

前端 未结 3 1426
醉话见心
醉话见心 2021-01-27 10:33

I\'m hitting problem with a reasonably straightforward vba macro for Microsoft Word which is designed to get around some issues we\'re seeing with list indentation when we creat

相关标签:
3条回答
  • 2021-01-27 10:42

    Your code looks OK and my sugestions will be just ideas to try doing the same another way...
    Idea 1: insert a DoEvents somewhere in the innerloop, to facilitate garbage collection.
    Idea 2: simplify your code by using FOR EACH constructs:

    For Each curlist in Lists
        For each curPar in curList.ListParagraphs
           With curPar.Range.ListFormat.ListTemplate
              .....
           End With
        Next curPar
    Next curList
    
    0 讨论(0)
  • 2021-01-27 10:51

    I've found a nasty, dirty solution that gets around the issue somewhat but is really a very poor fix. Basically, once we have gotten through one complete run of the macro, close and save the document and immediately reopen. This then allows the macro to be rerun immediately or at any stage because closing the document seems to eventually flush the memory properly. Obviously this can only be used if the user is happy to save as part of running the macro, but in my case it is

    0 讨论(0)
  • 2021-01-27 11:07

    Besides UndoClear, you can also save the document at each loop.

    It might heavily impact in your macro performance, though.

    There's a similar issue here http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/de7a88b4-914f-4895-a88a-659b732e8d87/

    Hope this helps.

    0 讨论(0)
提交回复
热议问题