OFF95: Illegal Operation Using Binder OLE Automation Object

Last reviewed: March 27, 1997
Article ID: Q132753
7.00 WINDOWS kbprg kbole kbcode

The information in this article applies to:

  • Microsoft Office for Windows 95, version 7.0
  • Microsoft Excel for Windows 95, version 7.0

SYMPTOMS

In Microsoft Excel, if you use a Visual Basic macro to create a Microsoft Office Binder OLE Automation object, you may receive an Illegal Operation error in Microsoft Excel. If you click Details, you may see information similar to the following:

   EXCEL caused an invalid page fault in module EXCEL.EXE at
   0137:5000d9fd.

CAUSE

This problem occurs if you create an Office Binder OLE Automation object, and you add a Microsoft Excel worksheet section to the Binder without dimensioning the Microsoft Excel section as an object to hold a pointer in memory for the object. For example, when you run the following macro, you receive an Illegal Operation error in Microsoft Excel:

   Sub BinderExample()
      Dim myBinder as Object, y as String
      ' Create Binder object
      Set myBinder = CreateObject("Office.Binder")
      ' Add Microsoft Excel worksheet section
      myBinder.sections.Add Type:="excel.sheet.5"
      y = myBinder.sections(1).Object.Name
      y = myBinder.sections(1).Object.Name
   End Sub

When you run the macro above, the myBinder.sections.Add statement correctly adds a worksheet section to the Binder. However, there is no pointer in memory for this object. The first reference to this section object occurs without an error, but the second reference to this object causes Microsoft Excel to crash.

Note that the above example is not the only example that causes an Illegal Operation error in Microsoft Excel. Other examples may include commands similar to the following:

   myBinder.sections(1).Visible = False
   myBinder.sections(1).Visible = True
   myBinder.Sections(1).Object.Parent.Worksheets.Add
   myBinder.Sections(1).Object.Parent.Worksheets(1).Range("A1").Value = "1"

WORKAROUND

To work around this behavior, when you add a Microsoft Excel worksheet section to a Binder using OLE Automation, dimension the worksheet section as Object type add so that a pointer in memory is reserved for this object. For example, to run the above macro without receiving an Illegal Operation error, modify the macro as follows:

   Sub BinderExample()
      Dim myBinder as Object, XLSec as Object, y as String
      ' Create Binder object
      Set myBinder = CreateObject("Office.Binder")
      ' Add Microsoft Excel worksheet section
      Set XLSec = myBinder.sections.Add(Type:="excel.sheet.5")
      y = myBinder.sections(1).Object.Name
      y = myBinder.sections(1).Visible = True
   End Sub

Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

REFERENCES

For more information about communicating with other applications in Microsoft Excel, click the Index tab in Microsoft Excel Help, type the following text

   CreateObject function

double-click the selected text, and then double-click "communicating with other applications" to go to the "Communicating With Other Applications" topic.


KBCategory: kbprg kbole kbcode kbfasttip
KBSubcategory: offwin

Additional reference words: 7.00 xl7 gpf crash

Keywords : offwin kbcode kbfasttip kbole kbprg
Version : 7.00
Platform : WINDOWS


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: March 27, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.