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

ID: Q94901

The information in this article applies to:

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

Last Reviewed: November 17, 1997