Microsoft KB Archive/159858

= XL97: Macro Error Accessing OLEObject on Worksheet =

Article ID: 159858

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Excel 97 Standard Edition

-



This article was previously published under Q159858



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 a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

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.  In Microsoft Excel 97, start a new workbook. Point to Toolbars on the View menu and click Control Toolbox to display the Control Toolbox toolbar. Click the Check Box control and drag over the worksheet to draw a check box. Right-click the check box and click Properties on the shortcut menu. Type MyBox as the Name property of the check box. Close the Properties window. Press ALT+F11 to activate the Visual Basic Editor.</li> Click Module on the Insert menu.</li>  Type the following code in the Code Window: Sub Test Activesheet.OLEObjects("MyBox").Object.Value = True End Sub </li> Click "Close and Return to Microsoft Excel" on the File menu.</li> 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.</li></ol>

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.

<div class="status_section">

STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. This problem no longer occurs in Microsoft Excel 2000.

<div class="moreinformation_section">

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: kbdtacode kberrmsg kbprogramming KB159858

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.