Microsoft KB Archive/832580

From BetaArchive Wiki
Knowledge Base


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.


RESOLUTION

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:

  1. Quit Word 2002.
  2. Click Start, and then click Run.
  3. In the Open box, type regedit, and then click OK.
  4. Locate and then click to select the following registry key:

    HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Word\Options

  5. Point to New on the Edit menu, and then click DWORD Value.
  6. Type AlternateReplaceAllMethodBehaviour, and then press ENTER.
  7. Right-click the AlternateReplaceAllMethodBehaviour registry value, and then click Modify.
  8. In the Value data box, use one of the following methods:
    • To prevent the problem that is described in the "Symptoms" section, type 0, and then click OK.
    • 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

  9. On the File menu, click Exit to quit Registry Editor.

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


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, "doc1.doc" and "doc2.doc". Edit and save the second document, doc2.doc. Instead of the following code,

Documents.Open "doc1.doc"
Documents.Open "doc2.doc"

[your macro code]

ActiveDocument.Close


use this code:

Documents.Open "doc1.doc"
Documents.Open "doc2.doc"

[your macro code]

Documents("doc2.doc").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("doc1.doc")
Set objDoc2 = Documents.Open("doc2.doc")

[your macro code]

objDoc2.Close


This will also make your code easier to read.

Keywords: kberrmsg kbbug kbfix kbqfe kbofficexppresp3fix KB832580