BUG: Automation client receives error or crashes calling Word's Find object (292744)



The information in this article applies to:

  • Microsoft Office Word 2003
  • Microsoft Word 2002
  • Microsoft Word 2000
  • Microsoft Word 97 for Windows
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Visual C++, 32-bit Professional Edition 6.0

This article was previously published under Q292744

SYMPTOMS

When you use an out-of-process client application that uses early binding to Automate Word 97 or later, the application may crash with an access violation or you may receive one of the following error messages:

From Microsoft Visual Basic:
Run-time error '-2147023113 (800706f7)':
The method '~' of object '~' failed
Run-time error '-2147023113 (800706f7)':
Method 'Execute' of object 'Find' failed
Run-time error 430:
Class does not support automation or does not support expected interface.
From Microsoft Visual C++:
HRESULT = 0x800706F7
RPC_X_BAD_STUB_DATA - The stub received bad data.
NOTE: In debug builds you receive a corrupt stack warning from an Assert dialog box, and the value of EAX is that listed above. In release builds, the stack corruption will likely crash the application soon after this point, but the HRESULT value is likely to be similar to the above.

The problem occurs consistently on some computers, but may never occur on others. Installing a new application or a Microsoft Excel service pack can cause a computer that was working previously to experience the problem.

CAUSE

Several globally unique identifiers (GUIDs) that are used by Word for its interface identifiers were used by Excel version 5.0 for an older object model that is now obsolete.

When the Excel 5.0 type library is reregistered on a system, the interface GUIDs in the registry that should point to the Word type library point to the Excel 5.0 library, and COM can mistakenly construct the wrong proxy v-table for an out-of-process client using early binding to Word. Calls that are made to this proxy return errors or crash because the proxy is configured for a dispinterface for Excel instead of for the expected Word interface.

The following GUIDs are duplicated in the Excel 5.0 type library and the Word 8.0, 8.1, 10.0 and 11.0 type libraries:

Interface ID (GUID) Word Interface Excel 5.0 Dispinterface
{000209B1-0000-0000-C000-000000000046} Replacement Worksheets
{000209AD-0000-0000-C000-000000000046} Dictionary Module
{000209AE-0000-0000-C000-000000000046} ReadabilityStatistics Modules
{000209AF-0000-0000-C000-000000000046} ReadabilityStatistic DialogSheet
{000209B0-0000-0000-C000-000000000046} Find DialogSheets

If the Word type library is properly registered, COM constructs the correct proxy and the out-of-process calls function normally.

RESOLUTION

To resolve this problem, do one of the following:
  • Modify your code to use late binding when you call methods or properties on any of the above listed Word interfaces. -or-

  • Reregister the Word type library on the system on which the problem occurs.
The recommended solution is to use late binding. Because both type libraries describe interfaces that implement the IDispatch interface, calls to any of the IDispatch methods work regardless of which library was last registered on the system. This is the only way to be sure that your code does not encounter this error on systems that you do not administer.

For customers that use client applications that cannot be recompiled to use late binding, you can reregister the Word type library to resolve the problem in most cases. Because the problem returns if the Excel 5.0 library is reregistered again, this is not an ideal resolution. However, the chances of the Excel 5.0 library being reregistered are low, so this method should work for most users.

To reregister the Word type library, find the appropriate type library for the version of Word that is installed on the system:

VersionLibrary Name
Word 97msword8.olb
Word 2000msword9.olb
Word 2002msword.olb
Word 2003msword.olb

Then, from the command line, use Regtlib.exe with the full path to the type library to reregister the library for COM. Regtlib.exe calls the LoadTypeLib and RegisterTypeLib application program interfaces (APIs) on the type library (.tlb or .olb) file that is passed in. COM repairs the misconfigured registry keys.

Regtlib.exe is included in the Windows Libraries Update. For additional information about the Libraries Update, click the following article number to view the article in the Microsoft Knowledge Base:

197298 INFO: Microsoft Libraries Update: What, Where, Why

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

The Excel 5.0 type library (Xl5en32.olb) is provided for backward compatibility, and is used by clients that were written before Excel 97. The type libraries for Excel 97 and later do not conflict with the Word type library. The Excel 5.0 library is not normally registered, so most clients do not encounter this problem. Clients that encounter this issue have probably installed a specific product that uses the library and has registered it after Office setup.

Steps to Reproduce Behavior

  1. Find the Excel 5.0 type library (Xl5en32.olb) and register it by typing Regtlib at a command prompt.
  2. In Visual Basic, create a Standard EXE project. Form1 is created by default.
  3. Add a button to Form1, and paste the following code in the code section for Form1:
    Private Sub Command1_Click()
       Dim oApp As Word.Application
       Dim oDoc As Word.Document
       Dim oSel As Word.Selection
          
       Set oApp = New Word.Application
       oApp.Visible = True
       
       Set oDoc = oApp.Documents.Add
       Set oSel = oApp.Selection
       
       oSel.TypeText "This is a test. You too can automate Word."
       oSel.Start = 0
       
       oSel.Find.Execute "Word", , , , , , True, _
          wdFindContinue, , "Microsoft Word 2000", wdReplaceAll
          
       MsgBox "Did it work?"
       
       Set oSel = Nothing
       oDoc.Saved = True
       oDoc.Close
       Set oDoc = Nothing
       
       oApp.Quit
       Set oApp = Nothing
       
    End Sub
    					
  4. On the Project menu, click References. In the References dialog box, select Microsoft Word 8.0 Object Library (or select the Word 9.0 Object Library, or the Word 10.0 Object Library, or the Word 11.0 Object Library) and click OK.
  5. Compile and run the code, or press F5 to run the code in the debugger. Click the command button, and you see the error listed in the "Symptoms" section.
  6. Fix the issue by reregistering the Word type library as described in the "Resolution" section, or replace the early-bound declaration of the Selection object to use late binding with the following code:
        Dim oSel As Object
    					

Modification Type:MajorLast Reviewed:3/23/2006
Keywords:kbAutomation kbbug kbnofix KB292744