WD: Out-of-Memory Error with Macro That Edits DocumentLast reviewed: November 17, 1997Article ID: Q94901 |
The information in this article applies to:
SYMPTOMSIn Microsoft Word for Windows, it is possible to receive an out of memory error while running a macro that performs a large number of edits to a document.
CAUSEThis out of memory error may be an indication that there are too many edits to the document, rather than an insufficient amount of memory.
RESOLUTIONTo eliminate this error, add a FileSave command to your macro so that the document is saved periodically. When using a macro to search and replace text in a document, the FileSave command is often needed after a number of replacements have been made. The FileSave command clears the Word edit buffer so that the macro can continue making edits. Below is a sample macro that replaces all semicolons with tabs in a document. The If statement and count variable are used to save the document after every 30 replacements.
Word 6.0
Sub MAIN ToolsOptionsSave .FastSaves = 0 StartOfDocument count = 0 EditFindClearFormatting EditFind .Find = ";", .Direction = 0 While EditFindFound() count = count + 1 EditClear Insert Chr$(9) If count = 30 Then FileSave count = 0 End If RepeatFind Wend End Sub Word 2.x
Sub MAIN ToolsOptionsSave .FastSaves = 0 StartOfDocument count = 0 EditFindClearFormatting EditFind .Find = ";", .Direction = 2 While EditFindFound() count = count + 1 EditClear Insert Chr$(9) If count = 30 Then FileSave count = 0 End If EditFind .Find = ";", .Direction = 2 Wend End SubWARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
REFERENCES"Using WordBasic," by WexTech Systems and Microsoft, pages 180, 181, 333-334.
|
Additional query words: memory error WordBasic errmsg winword2 winword 7.0
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |