Microsoft KB Archive/832580

= Word 2002 stops responding and you receive an error message when you run a VBA macro that uses the .ReplaceAll property =

Article ID: 832580

Article Last Modified on 7/1/2005

-

APPLIES TO


 * Microsoft Word 2002 Standard Edition

-





SYMPTOMS
When you run a Microsoft Visual Basic for Applications (VBA) macro that uses the .ReplaceAll property in Microsoft Word 2002, Word 2002 may stop responding (hang), and then you receive the following error message:

Microsoft Word has encountered a problem and needs to close. We are sorry for the inconvenience.

If you view the details of the error message, you receive an error signature that is similar to the following:   AppName      AppVer       ModName      ModVer       Offset Winword.exe 10.0.5522.0  Winword.exe  10.0.5522.0  000170d6



CAUSE
This problem may occur if all the following conditions are true:
 * The macro uses the .ReplaceAll property of the Find object.
 * The Find and Replace action is performed on more than one document in the macro.
 * There are several documents open while the macro is running.
 * The macro uses the ActiveDocument object to refer to a specific document.
 * The 815006 hotfix or the Word 2002 security update is installed.



How to obtain the hotfix
This issue is fixed in the Word 2002 post-Service Pack 3 Hotfix Package May 5, 2004. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

830807 Word 2002 post-Service Pack 3 hotfix package: May 5, 2004



MORE INFORMATION
To set the AlternateReplaceAllMethodBehaviour registry value, follow these steps:  Quit Word 2002. Click Start, and then click Run. In the Open box, type regedit, and then click OK. Locate and then click to select the following registry key:

 

 Point to New on the Edit menu, and then click DWORD Value.</li> Type AlternateReplaceAllMethodBehaviour, and then press ENTER.</li> Right-click the AlternateReplaceAllMethodBehaviour registry value, and then click Modify.</li> In the Value data box, use one of the following methods: <ul> To prevent the problem that is described in the &quot;Symptoms&quot; section, type 0, and then click OK.</li> To prevent the problem that is described in the following article in the Microsoft Knowledge Base, type 1, and then click OK.

815006 WD2002: VBA Find.Execute ReplaceAll method does not return the original selection

</li></ul> </li> On the File menu, click Exit to quit Registry Editor.</li></ol>

For additional information about the 815006 hotfix, click the following article number to view the article in the Microsoft Knowledge Base:

815006 WD2002: VBA Find.Execute ReplaceAll method does not return the original selection

For additional information about the Word 2002 security update, click the following article number to view the article in the Microsoft Knowledge Base:

824934 Overview of the Word 2002 Security Patch: September 3, 2003

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

824684 Description of the standard terminology that is used to describe Microsoft software updates

<div class="workaround_section">

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 work around this problem, do not use the ActiveDocument object in your VBA macro or in automation to refer to a specific document when several documents are open in Word 2002. Instead, use the objects in the Documents collection to specify a document by name.

For example, assume that you are opening two documents, &quot;doc1.doc&quot; and &quot;doc2.doc&quot;. Edit and save the second document, doc2.doc. Instead of the following code, Documents.Open &quot;doc1.doc&quot; Documents.Open &quot;doc2.doc&quot;

[your macro code]

ActiveDocument.Close

use this code: Documents.Open &quot;doc1.doc&quot; Documents.Open &quot;doc2.doc&quot;

[your macro code]

Documents(&quot;doc2.doc&quot;).Close

When you refer to the same document several times in your code, it is a good idea to define an object variable and set this to the document so that you can use the name of the variable whenever you want to refer to this specific document. See the following example: Dim objDoc1 As Document, objDoc2 As Document Set objDoc1 = Documents.Open(&quot;doc1.doc&quot;) Set objDoc2 = Documents.Open(&quot;doc2.doc&quot;)

[your macro code]

objDoc2.Close

This will also make your code easier to read.

Keywords: kberrmsg kbbug kbfix kbqfe kbofficexppresp3fix KB832580

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.