Microsoft KB Archive/279680

From BetaArchive Wiki
Knowledge Base


Out-of-memory error message with macro that edits document

Article ID: 279680

Article Last Modified on 8/14/2007



APPLIES TO

  • Microsoft Office Word 2003
  • Microsoft Word 2002 Standard Edition



This article was previously published under Q279680

For a Microsoft Word 97 version of this article, see 279675.

For a Microsoft Word 2000 version of this article, see 279677.

SYMPTOMS

In Microsoft Word, you may receive an out-of-memory error message while you are running a macro that performs a large number of edits to a document.

CAUSE

This out-of-memory error message may indicate that the document contains too many edits, rather than an insufficient amount of memory.

WORKAROUND

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To prevent this error message from appearing, add a Save method to your macro so that the document is saved periodically.

When you use a macro to search for and replace text in a document, the Save method is often needed after a number of replacements have been made. The Save method clears the Word edit buffer, so that the macro can continue making edits.

The following example macro replaces all semicolons with tabs in a document. The If statement and count variable are used to save the document after every 30 replacements.

Sub UpdateCount()

Dim count As Integer

count = 0

Options.AllowFastSave = False
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Execute findtext:=";", Forward:=True

While Selection.Find.Found = True
   count = count + 1
   Selection.TypeText Text:=vbTab

   If count = 30 Then
      ActiveDocument.Save
      count = 0
   End If

   Selection.Find.Execute
Wend

End Sub
                


Additional query words: memory error errmsg err msg insufficient out of prb WD2002 WD2003

Keywords: kbnofix kbmacroexample kbprb KB279680