Microsoft KB Archive/125179

= Finding Graphic Objects Within a Range with TopLeftCell =

Article ID: 125179

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Excel 97 Standard Edition
 * Microsoft Excel 95 Standard Edition
 * Microsoft Excel 5.0 Standard Edition
 * Microsoft Excel 98 for Macintosh

-



This article was previously published under Q125179



SUMMARY
Graphic objects, such as charts or text box objects, are drawn on the object layer of a worksheet. The object layer is above the worksheet cells. In Microsoft Visual Basic for Applications, you can determine the object's cell coordinates by using the TopLeftCell property.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements. The following Visual Basic macro (Sub procedure) determines whether a graphic object is within the print range. If it is, the object is deleted. The TopLeftCell property returns the cell that is under the top left portion of the graphic object.

The items on a worksheet that would be considered part of the graphic objects collection include:

Arc, Button, ChartObject, CheckBox, Drawing, DropDown, GroupBox, GroupObject, Label, Line, ListBox, OLEObject, OptionButton, Oval, Picture, Rectangle, ScrollBar, Spinner, and TextBox.

Sample Visual Basic Procedure
Sub DeleteObjects ' Define a For-Each loop of all the drawing objects on the ' active worksheet. For Each DrawObj In ActiveSheet.DrawingObjects ' Define Cell_Ref as the top left cell address of each Drawing ' Object. Cell_Ref = DrawObj.TopLeftCell.Address ' Define a For-Each loop of all the cells with the range ' Print_Area. For Each Cell In Range("Print_Area") ' If the Object's top left cell address is the same as a              ' cell in the print range. If Cell_Ref = Cell.Address Then ' Then delete the object. DrawObj.Delete ' End the IF statement. End If          ' Loop through next cell. Next Cell ' Loop through next DrawObj. Next DrawObj End Sub

Additional query words: 5.00c XL97 XL98 XL7 XL5 XL

Keywords: kbdtacode kbhowto kbprogramming KB125179

-

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

© Microsoft Corporation. All rights reserved.