XL97: Macro Error Accessing OLEObject on Worksheet

Last reviewed: March 13, 1998
Article ID: Q159858
The information in this article applies to:
  • Microsoft Excel 97 for Windows

SYMPTOMS

You may receive the following error when you run a Visual Basic for Applications macro that accesses an OLEObject on a worksheet:

   Run-time error '1004':
   Unable to get the OLEObjects property of the Worksheet class

CAUSE

To access an OLE object on a worksheet using the OLEObjects method, you must specify the drawing object name for the object. The drawing object name is the name that appears in the Name box when the worksheet object is selected.

You may receive the error described if you do not use the "drawing object name" with the OLEObjects method.

RESOLUTION

Microsoft provides examples of Visual Basic for Applications 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

If you change the Name property for an OLE object on your worksheet, you should also change the drawing object name so that the names are the same.

The following steps illustrate how this problem may occur and how you can correct it.

  1. In Microsoft Excel 97, start a new workbook.

  2. Point to Toolbars on the View menu and click Control Toolbox to display the Control Toolbox toolbar.

  3. Click the Check Box control and drag over the worksheet to draw a check box.

  4. Right-click the check box and click Properties on the shortcut menu.

  5. Type "MyBox" (without quotation marks) as the Name property of the check box. Close the Properties window.

  6. Press ALT+F11 to activate the Visual Basic Editor.

  7. Click Module on the Insert menu.

  8. Type the following code in the Code Window:

           Sub Test()
               Activesheet.OLEObjects("MyBox").Object.Value = True
           End Sub
    
    

  9. Click "Close and Return to Microsoft Excel" on the File menu.

  10. Point to Macro on the Tools menu and click Macros. Select the macro named Test and click Run to run the macro. You will receive the run- time error described earlier in this article.

To correct the problem so that the macro runs successfully, you should change the drawing object name of the check box to MyBox. To do this, use the following steps:

  1. Click the Design Mode toolbar button on the Control Toolbox toolbar.

  2. Select the check box.

  3. Type MyBox in the Name box of the Formula bar and press Enter.

  4. Point to Macro on the Tools menu and click Macros. Select the macro named Test and click Run to run the macro. The macro will run successfully.

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.

MORE INFORMATION

The Name box is the box at the left end of the formula bar that identifies the selected cell, chart item or drawing object. To display the Name box, click Options on the Tools menu, click the View tab, select Formula Bar and click OK.


Additional query words: XL97 8.00 checkbox command button text box
textbox option optionbutton list listbox combo combobox toggle spin spinner
scroll scrollbar label image ActiveX
Keywords : kbcode kberrmsg kbprg xlvbainfo xlui
Version : WINDOWS:97
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 13, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.