Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Memory leaks? (Word97/NT)

    Hi

    I've developed a complex set of VisualBasic for Word macros. The macros work, but after a while problems start appearing (typically, "cannot open macro storage" and "activedocument.save" fails).

    In some situations, the macros close the active document and open a different document (pointing at the same template). I suspect that I'm not closing tidily enough, which is causing memory leakage.

    Is there a useful resource that would tell me about closing down efficiently. Something that will answer questions like:
    <UL><LI>Does an "End" statement close everything down tidily?
    <LI>Does closing the active document close everything down tidily?
    <LI>Would I be better to Unload forms before closing the document (programmatically)?
    <LI>Etc, etc[/list]Thanks for your help
    Dale

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Memory leaks? (Word97/NT)

    Dale,

    It will probably be hard for anyone to provide specific advice without knowing more details about what you're doing - is it possible to post some relevant chunks of code?

    Speaking generally: an "End" statement should suffice (since VBA should release memory allocated to variables which go out of scope) but the consensus is that it's not good practice to rely on this - so for example an object variable assigned using "Set" should be explicitly destroyed ("Set object = Nothing") before the procedure ends.

    Similar for closing an active document; it should close things tidily but one can imagine odd circumstances where you could 'confuse' VBA - for example if you run code that's in the active document's attached template, and that code at some point creates a new document based on the same template and closes the original document - it's possible to see how this might lead to a problem unless object references for each document are carefully created and destroyed.

    Similarly for unloading forms - depends on where the form 'lives': if you've got the form in a global template and it has to stay open as documents based on other templates are opened/closed, that's probably safe enough. But if the userform 'lives' in an attached template and you're doing things like closing the original activedocument that was in effect when the userform was initialized, while opening another document based on the same attached template, again that might be courting trouble.

    - the above are just general rules of thumb....hope this is at all helpful.

    Gary

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Memory leaks? (Word97/NT)

    That's very useful, thanks, Gary.
    Dale

Posting Permissions

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