XL97: Macro Error Accessing OLEObject on Worksheet (159858)
The information in this article applies to:
- Microsoft Excel 97 for Windows
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.
RESOLUTIONMicrosoft 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:
For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:
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.
- Click Module on the Insert menu.
- Type the following code in the Code Window:
Sub Test()
Activesheet.OLEObjects("MyBox").Object.Value = True
End Sub
- Click "Close and Return to Microsoft Excel" on the File menu.
- 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:
- Click the Design Mode toolbar button on the Control Toolbox toolbar.
- Select the check box.
- Type MyBox in the Name box of the Formula bar and press Enter.
- 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. This problem no longer occurs in
Microsoft Excel 2000.
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.
Modification Type: | Minor | Last Reviewed: | 10/10/2006 |
---|
Keywords: | kbdtacode kberrmsg kbProgramming KB159858 |
---|
|