Knowing Name of Shape with VBA

prajul89

Active Member
Joined
Jul 9, 2011
Messages
404
Hi,
How to know the name of the Shapes (Rectangle) in a particular range with macro.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi - could record macro & select the shape, code will then tell you what you the name
 
Upvote 0
Not exactly sure what you are after, but see if you can make use of one of these (see the macro's name)...

Code:
Sub GetShapesWhoseSurroundingRectangleTouchesTheSelectedRangeSomewhere()
  Dim SH As Shape, ShapesInRange As String
  For Each SH In ActiveSheet.Shapes
    If Not Intersect(Range(SH.TopLeftCell.Address & ":" & SH.BottomRightCell.Address), Selection) Is Nothing Then
      ShapesInRange = ShapesInRange & SH.Name & vbLf
    End If
  Next
  If Len(ShapesInRange) Then
    MsgBox ShapesInRange
  Else
    MsgBox "There are no shapes in that range!"
  End If
End Sub
 
Sub GetShapesThatAreCompletelyWithinTheSelectedRangeOfCells()
  Dim SH As Shape, ShapesInRange As String, Intersection As Range
  For Each SH In ActiveSheet.Shapes
    Set Intersection = Intersect(Range(SH.TopLeftCell.Address & ":" & SH.BottomRightCell.Address), Selection)
    If Not Intersection Is Nothing Then
      If Intersection.Address = Range(SH.TopLeftCell.Address & ":" & SH.BottomRightCell.Address).Address Then
        ShapesInRange = ShapesInRange & SH.Name & vbLf
      End If
    End If
  Next
  If Len(ShapesInRange) Then
    MsgBox ShapesInRange
  Else
    MsgBox "There are no shapes in that range!"
  End If
End Sub
Note that each macro will list all the shapes that meet the condition the macro is looking for (again, read each macro's name to see what that is).
 
Upvote 0
One way:

Code:
Sub x()
    Dim shp As Shape
    
    For Each shp In ActiveSheet.Shapes
        If Not Intersect(shp.TopLeftCell, Range("A1:A10")) Is Nothing Then
            shp.Select
            MsgBox shp.Name
        End If
    Next shp
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top