Memory usage - how to control (VBA 6.5) RRS feed

  • Question

  • Hi All,

    I have written some VBA that will break down a mail merged letter into individual letters and send these to a web service for processing.

    The vba script will read each line of the document and separate the letter based on an identifier at the top and bottom. The document is then stored in an array in memory. Once the letter has been split into individual letters each item in the array is read and sent to the web service, and then is closed without saving.

    However the process of closing the letters is very slow! If I don't close the letters and just attempt to empty the array (Erase documentList) it doesn't seem to reduce the memory used (so i'm guessing it is still in memory - checked using Task Manager and looking at the Mem Usage column on the WINWORD.EXE Image name).

    Is there any way to quickly close down/remove all the documents from memory?

    Thanks in advance.

    Friday, November 8, 2013 3:52 PM

All replies

  • If you create object, you can clean memory like this:

    Dim WDApp As Object
    Set WDApp = CreateObject("Word.Application")
        WDApp.Documents.Open fileName:="C:/temp/_xxxxx.doc"
    'do something
        WDApp.Close True
    Set WDApp = Nothing 'clean memory

    Anyway after finish procedure all object are cleaned via garbage-collector mechanism.

    In Loop you can use Set oName = Nothing

    Oskar Shon, Office System MVP -
    if Helpful; Answer when a problem solved

    Tuesday, November 19, 2013 2:24 PM