none
How to speed up word VBA code? RRS feed

  • Question

  • I've seen many questions on this topic but few (no) good answers. I ran a number of tests before coming up with the following method to accelerate my macros when processing large word documents.  I'm interested in additional input on how to accelerate Word VBA.

    Sub Options_Off()
        Word.Application.ScreenUpdating = False
        Word.Application.Options.CheckGrammarAsYouType = False
        Word.Application.Options.CheckGrammarWithSpelling = False
        Word.Application.Options.CheckSpellingAsYouType = False
        Word.Application.Options.AnimateScreenMovements = False
        Word.Application.Options.BackgroundSave = False
        Word.Application.Options.CheckHangulEndings = False
        Word.Application.Options.DisableFeaturesbyDefault = True
    End Sub


    Jeff Abbott Systems Architect CAE Professional Services 2603 Discovery Drive Orlando, FL 32826 jeff.abbott@caemilusa.com Work: 407-745-2605 Cell: 407-222-7909 "We are often better served by connecting ideas than we are by protecting them." -Steven Johnson, Where Good Ideas Come From: The Natural History of Innovation

    Monday, September 17, 2018 6:47 PM

All replies

  • Of the code you posted, only Application.ScreenUpdating = False is likely to make a material difference in execution time. Of far greater benefit is avoiding the use of Select and Selection wherever possible. For long operations, inserting DoEvents at an appropriate juncture will also give Word some breathing space for its housekeeping. Similarly, when working with tables, it is beneficial to set the table's AllowAutoFit property to false (restoring it afterwards, if appropriate)

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Monday, September 17, 2018 11:38 PM
  • Hi JB Abbott,

    Thanks for macropod reply. You can try the solution provided by macropod.

    There are few ways to improve performance of VBA code.

    You can review the following link for reference:

    My Macro's code needs something to speed it up (MS word / VBA)

    Making Macros Run Faster

    Speeding up VBA for loop in Word

    Hopefully it helps you.

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.


    • Edited by Lina-MSFT Tuesday, September 18, 2018 7:11 AM
    Tuesday, September 18, 2018 2:40 AM
  • Hi JB Abbott,

    Thanks for your asking. Please remember to mark the replies(Include your solution) as answers if they helped and please help us close the thread.

     

    Thank you for understanding. If you have any question, or update, please feel free to let us know.

     

    I wish you a happy life!

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Thursday, September 20, 2018 2:44 AM