locked
Word - Insufficient memory exception. RRS feed

  • 问题

  • Hi,
    I'm facing a problem while automating MS Word to generate huge
    documents(sometimes may contain 1000 pages) which contains text, images etc.,

    To fix the problem, I have linked all the images in the word document, and
    also linked all the files(another word documents) that i do insert in the
    process of automation, but still the problem is not fixed.

    Moreover, if i proceed for 2 times, "Call was Rejected by Callee"
    RPC_E_CALL_REJECTED exception is being thrown and the automation process is
    getting stopped.


    Kindly let me know how can i solve this issue asap as its very urgent.


    Thanks
    Best Regards
    2008年5月7日 4:17

答案

  • Besides streamlining your code (using a single style to apply formatting instead of single steps is one example) about the only thing you can do is build a Document.Save into your code at "strategic points". It can also help to run the UndoClear method on the Document at the same time.

     

    The type of problem you describe usually comes from the fact that Word's temp, scratch and Undo buffer files have reached a limit. Forcing the document to do a full save and clearing the Undo buffer are about the only things that can help.

    2008年5月7日 7:36

全部回复

  • Hi,
    When i removed all the .tmp files in the ../Local Settings/temp folder, atleast the automation process is continuing. But Word is displaying MessageBoxes multiple times that it has insufficient memory, if i press "Continue" every time, the automation process will run and finally generates word document(approx 1200 pages).

    Is there any way to capture this exception/message from Word and programmatically "Continue"?



    Thanks,
    Best Regards
    2008年5月7日 6:35
  • Besides streamlining your code (using a single style to apply formatting instead of single steps is one example) about the only thing you can do is build a Document.Save into your code at "strategic points". It can also help to run the UndoClear method on the Document at the same time.

     

    The type of problem you describe usually comes from the fact that Word's temp, scratch and Undo buffer files have reached a limit. Forcing the document to do a full save and clearing the Undo buffer are about the only things that can help.

    2008年5月7日 7:36
  • Hi Cindy,
    Thanks for the answer, it worked for me magically.
    I should say, everytime i get problem with Word Automation, you always answered my queries.
    Thanks for your support.

    And - i have one more questionSmile
    Is it possible to create a section and define specific styles for that section? And also is it possible to insert a word document into that section so that, once inserted, all the document content should have those specific section styles and formatting?
    Can you please let me know how can i do this, as this can improve my automation performance significantly.


    Thanks a lot,
    Best Regards,








    2008年5月7日 14:48
  •  Ram Kumar K wrote:
    Hi Cindy,
    Is it possible to create a section and define specific styles for that section? And also is it possible to insert a word document into that section so that, once inserted, all the document content should have those specific section styles and formatting?
    Can you please let me know how can i do this, as this can improve my automation performance significantly.

    No, it's not possible to define a set of styles specific for a section of a document.

     

    The only way I know of to insert a document that's "pre-formatted" would be to first open that document, apply the formatting, save and close it, then insert it. Important would be that you either use a set of style names already pre-defined the way you want them in the "big" document, or a set of style names that does not (yet) exist in the "big" document. (Word should, by default, import any styles not already present in another document when inserting that document. If the styles already exist in the target document, those style definitions will over-write styles having the same name in the document being inserted.)

     

    If I had to do this, I'd probably set up a template that contains the entire set of styles I require. If the "big" document is being created from scratch, I'd create it from this template. And when I open the document to insert, I'd attach the template to it (AttachedTemplate property) then copy the styles I require into the document (Application.OrganizerCopy method). Doing this means that I wouldn't have to code the styles.

    2008年5月8日 11:23
  • Cindy,

    I'm using WORD 2010-2016. Is there a way to not even let my VSTO to store those changes in the undo list?

    My add-in first creates a copy of the active WORD doc -->make necessary style changes etc to the temp doc and then creates a pdf out of it. What I'm thinking is that during this processing, I programmatically first turn off the undo/redo feature on the temp doc and then at the end turn the feature on. That way, I won't have to call tempDoc.UndoClear() at multiple places.

    2020年3月19日 22:22