OFF95: Illegal Operation Using Binder OLE Automation Object

ID: Q132753


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.

Additional query words: xl7 gpf crash

Keywords : offwin
Version : 7.00
Platform : WINDOWS
Issue type :


Last Reviewed: June 3, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.