XL97: Macro Error Accessing OLEObject on Worksheet

ID: Q159858

The information in this article applies to:

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 programming examples 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 article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/

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.

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          : kberrmsg kbprg kbdta kbdtacode xlui KbVBA 
Version           : WINDOWS:97
Platform          : WINDOWS

Last Reviewed: May 18, 1999