Understanding Selection "Type"

  • Thread starter Thread starter MWE
  • Start date Start date
M

MWE

How can one determined what "type" of selection has been made? Since a
selection could be a range, a shape, a chartobject, etc., how do you
know which type and how can you determine which particular instance of
that type?

Thanks
 
TypeName is what you're after:

Sub test()
MsgBox TypeName(Selection)
End Sub

Another way is:
If TypeOf Selection Is Rectangle Then MsgBox "Selection is a Rectangle"
 
Ron: Your reply was most helpful. However, I still can
not quite do what I want. Assume a worksheet on which
there are various objects, e.g., charts, pictures,
textboxes, rectangles, etc. I wish to be able to select
any of these objects and know its "type" (you already
showed me how to do that) and be able to work with that
specific object. For a range or chart, working with the
selected object is understood (active cell, activechart,
etc). But for a item that the worksheet includes in its
collection of shapes, I do not know how to identify the
specific instance.

Thanks
-----Original Message-----

TypeName is what you're after:

Sub test()
MsgBox TypeName(Selection)
End Sub

Another way is:
If TypeOf Selection Is Rectangle Then
MsgBox "Selection is a Rectangle"
 
Back
Top