FIX: Microsoft Excel 95 Doesn't Respond Correctly to GetObject

Last reviewed: October 29, 1997
Article ID: Q153025
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 32-bit only, for Windows, version 4.0
  • Microsoft Excel 95, version 7.0

SYMPTOMS

Attempting to use the GetObject function to return a reference to a running instance of Microsoft Excel 95 results in the error 429:

   "OLE Automation server can't create object."

The identical code works correctly with a running instance of Microsoft Excel 5.0.

CAUSE

Microsoft Excel 95 fails to correctly register itself in the Running Object Table. The GetObject function can be used with the correct syntax to obtain a currently running instance of Microsoft Excel 95 for use with OLE automation.

Microsoft Excel 95 requires one additional step to ensure that it will respond to the OLE request. The code outlined below uses the SendMessage API to tell Microsoft Excel 95 to listen for requests for objects.

RESOLUTION

To work around this problem, follow these steps:

  1. Add a single code module to the current project. Alternatively, if a code module already exists, it can be used instead.

  2. Add the following code to the code module referred to in step 1:

          Const WM_USER = 1024
    

          Declare Function FindWindow Lib "user32" Alias "FindWindowA"_
          (ByVal lpClassName As String, ByVal lpWindowName As Long) As Long
          Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
          (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
          lParam As Long)
          As Long
    

          Sub WakeExcel()
               Dim hwnd As Long
    
               hwnd = FindWindow("XLMAIN", 0)
               If hwnd = 0 Then
                  'no instances running
                  Exit Sub
               End If
               SendMessage hwnd, WM_USER + 18, 0, 0
          End Sub
    
    

  3. Add a call to the WakeExcel function so that it is called after a user may have started Microsoft Excel, but before the call to GetObject is made.

STATUS

Microsoft has confirmed this to be a bug in Microsoft Excel 95. This bug has been fixed in Microsoft Excel 97.

MORE INFORMATION

Steps to Reproduce Problem

  1. Start a new instance of Visual Basic 4.0. Form1 is created by default.

  2. Add the following code to the Form_Click event of Form1:

          Private Sub Form_Click()
    
              Dim o As Object
    
              Set o = GetObject(, "Excel.Application")
              Set o = Nothing
          End Sub
    
    

  3. Ensure that Microsoft Excel 95 is running.

  4. Press the F5 key to run the application. Click the form once, and note the error outlined above.

REFERENCES

For additional information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE ID: Q114347
   TITLE     : INFO: OLE Automation Objects with GetObject and CreateObject


Additional query words: GetActiveObject
Keywords : kberrmsg kbprg GnrlVB
Technology : kbole kbvba
Version : WINDOWS:4.0
Platform : NT WINDOWS
Issue type : kbbug
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.