WD: Out-of-Memory Error with Macro That Edits Document

Last reviewed: November 17, 1997
Article ID: Q94901
The information in this article applies to:
  • Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, version 7.0
  • Word for the Macintosh, versions 6.0, 6.0.1

SYMPTOMS

In 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.

CAUSE

This out of memory error may be an indication that there are too many edits to the document, rather than an insufficient amount of memory.

RESOLUTION

To 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 Sub

WARNING: 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
word95 err msg insufficient macword 6.0.1 word7 word6 out of memory
Keywords : kbmacro
Version : WINDOWS: 2.x, 6.0, 6.0a, 6.0c, 7.0; MACINTOSH: 6.0, 6.0.1
Platform : MACINTOSH WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.