get the name of the shape so i can use in my vba code

ilcaa

Well-known Member
Joined
May 25, 2005
Messages
751
Office Version
  1. 365
Platform
  1. Windows
i inserted 2 arrows into my worksheet, i want to reference the name... i cant seem to find the name, i figure in the properties dialog box it would exist but that would make too much sense. i used this code i found but the msgbox is empty
<code>
CallingShapeName = ActiveSheet.Shapes(Application.Caller).Name
MsgBox CallShapeName
</code>

its 2 simple arrows, 1 points left, 1 points right, they are both blue. i took them from the shapes drop down box in the Insert menu. where can i find the name!? thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Once you select your shape, you should see the name of the shape in the Name Box, which is located on the far left side of the formula bar. If you don't see it, enable it as follows...

Code:
File > Options > Advanced > Display

...and check/select Show formula bar.
 
Upvote 0
If you need to do it via VBA, this works for me
Code:
Sub GetName()
Dim Nme As String
Nme = ActiveSheet.Shapes(Application.Caller).name
MsgBox Nme
End Sub
 
Last edited:
Upvote 0
thanks, now i assigned the same macro to 2 arrow shapes. I am trying to do a basic if shapes.name = "xx" then, but its wrong, i also tried
If ActiveSheet.Shapes(Application.Caller).Name = "Left Arrow 1" Then... that doenst work...

<code>
If ActiveSheet.Shapes(Application.Caller).Name = "Left Arrow 1" Then
Run "shift_VizLOD_toLeft"
End If
'---------------------------------------------------
If ActiveSheet.Shapes(Application.Caller).Name = "Right Arrow 3" Then
Run "shift_VizLOD_toRight"
End If
</code>
 
Upvote 0
Another way is to select the shape and then check its name in the Selection pane (ALT + F10) and change it to whatever you want by making a double click there...
Afterwards you will be able to reference it by name in your code.
 
Upvote 0
If you need to do it via VBA, this works for me
Code:
Sub GetName()
Dim Nme As String
Nme = ActiveSheet.Shapes(Application.Caller).name
MsgBox Nme
End Sub
Hi. When I run this, I get the following error. Any idea why?
1704312120517.png
 
Upvote 0
Please start a new thread for this question.
 
Upvote 0

Forum statistics

Threads
1,224,748
Messages
6,180,721
Members
452,995
Latest member
isldboy

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