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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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
In what way doesn't it work?
 
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,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

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