Article ID: 279675 - Last Review: January 29, 2007 - Revision: 2.3

WD97: Out-of-Memory Error Message with Macro That Edits Document

System TipThis article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
This article was previously published under Q279675
Expand all | Collapse all

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

The out-of-memory error message may indicate that there are too many edits in the document, 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.
For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:
173707  (http://support.microsoft.com/kb/173707/EN-US/ ) OFF97: How to Run Sample Code from Knowledge Base Articles
To prevent an out-of-memory error message, 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 sample 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
				

REFERENCES

For additional information about available resources for creating customsolutions by using Visual Basic for Applications, click the article numbers below to view the articles in the Microsoft Knowledge Base:
163425  (http://support.microsoft.com/kb/163425/EN-US/ ) WD97: Macro Programming Resources
163435  (http://support.microsoft.com/kb/163435/EN-US/ ) VBA: Programming Resources for Visual Basic for Applications

APPLIES TO
  • Microsoft Word 97 Standard Edition
Keywords: 
kbmacro kbmacroexample kbnofix kbprb KB279675
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.