Word 2002 stops responding and you receive an error message when you run a VBA macro that uses the .ReplaceAll property (832580)
The information in this article applies to:
SYMPTOMSWhen 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
CAUSEThis 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.
RESOLUTIONHow to obtain the hotfixThis 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 WORKAROUNDMicrosoft 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.
Modification Type: | Major | Last Reviewed: | 7/1/2005 |
---|
Keywords: | kberrmsg kbQFE kbbug kbfix kbofficexppresp3fix KB832580 kbAudEndUser kbAudDeveloper |
---|
|