'Retrieve the name of a shape
In Excel we have the "Name Box" in the upper-left side, but I could not find a way to retrieve the name of a shape in Word. How do I do that?
Solution 1:[1]
There are two types of shapes in MS Word- InlineShapes and Shapes. It's quite easy to check name of shape object with some VBA code:
- select shape
- press Alt+F11 to open VBA Editor
- in Immediate window execute this code:
? Selection.ShapeRange.Name - as a result you get name of the shape.
InlineShape doesn't have name property therefore you can't check it's name until you promote your InlineShape to Shape type object.
Solution 2:[2]
Microsoft Word 2010 onwards
From Microsoft Word 2010 onwards (2010, 2013 and 2016) there is an "Selection Pane" in Microsoft Word.
On the selection pane the Microsoft Word InlineShapes as well as the Shapes are listed and named. Clicking on one of the shape names allows you to change them.
You can find the Selection Pane in the menu under
- "Home"-tab
- "Editing"-group
- "Select"-button
- "Selection Pane..."
Microsoft Word versions before 2010
For older Microsoft Word (2003, 2007) versions use the VBA approach (?Selection.ShapeRange.Name) as Kazimierz Jawor posted as an other answer to this question: https://stackoverflow.com/a/17680650/1306012
- Select the shape
- Open the VBA editor by pressing Alt+F11
- Open the immediate window by pressing Ctrl+G
- Type
?Selection.ShapeRange.Namein the immediate window to get the shape name
Solution 3:[3]
The most convenient method is to create a macro button, which is accessible from your tabs (e.g., Home, Insert, etc.). This way, you just click on the shape, click the macro button, and voila - the shape name displays in a message box (pop up window).
Use the following code:
MsgBox ActiveWindow.Selection.ShapeRange(1).name
Solution 4:[4]
Correct answer, I hope)))
For Each ILShp In Doc.InlineShapes
If ILShp.Type = 5 Then ' 5 (wdInlineShapeOLEControlObject) - OLE control object. (ComboBox and CheckBox)
' if object is ComboBox
If CStr(ILShp.OLEFormat.ClassType) = "Forms.ComboBox.1" Then
Cb_Name = ILShp.OLEFormat.Object.Name ' retuns ComboBox1
endif
Next
Solution 5:[5]
Word 2007 Works for pictures and haven't tested the rest
Sub S___FindShapetypeOfSelectedShape()
'1======= msgbox if floating shape selected
On Error GoTo NOT_FLOATING_SHAPE 'go to check for inline shape
MsgBox "Floating shape, " & ActiveWindow.Selection.ShapeRange(1).Name '"Picture 1480"; blue dottedlines= "picture 4"
Exit Sub
NOT_FLOATING_SHAPE:
'on error goto 0 'use for testing
On Error GoTo NO_SHAPE_FOUND 'doesnt work???
'2.=========
MsgBox "Inline Shape type NUMBER = " & ActiveWindow.Selection.InlineShapes(1).Type '
'2a_________check for each type of inline shape
'!!!(to see if msgbox draft below can be fixed)
If ActiveWindow.Selection.InlineShapes(1).Type = wdNoSelection Then
MsgBox "No selection"
Exit Sub
ElseIf ActiveWindow.Selection.InlineShapes(1).Type = wdInlineShapeChart Then
MsgBox "wdInlineShapeChart"
Exit Sub
ElseIf ActiveWindow.Selection.InlineShapes(1).Type = wdInlineShapeDiagram Then
MsgBox "wdInlineShapeDiagram"
Exit Sub
ElseIf ActiveWindow.Selection.InlineShapes(1).Type = wdInlineShapeEmbeddedOLEObject Then
MsgBox "wdInlineShapeEmbeddedOLEObject"
Exit Sub
ElseIf ActiveWindow.Selection.InlineShapes(1).Type = wdInlineShapeHorizontalLine Then
MsgBox "wdInlineShapeHorizontalLine"
Exit Sub
ElseIf ActiveWindow.Selection.InlineShapes(1).Type = wdInlineShapeLinkedOLEObject Then
MsgBox "wdInlineShapeLinkedOLEObject"
Exit Sub
ElseIf ActiveWindow.Selection.InlineShapes(1).Type = wdInlineShapeLinkedPicture Then 'EMPTY FRAMES?
MsgBox "wdInlineShapeLinkedPicture"
Exit Sub
ElseIf ActiveWindow.Selection.InlineShapes(1).Type = wdInlineShapeLinkedPictureHorizontalLine Then
MsgBox "wdInlineShapeLinkedPictureHorizontalLine"
Exit Sub
ElseIf ActiveWindow.Selection.InlineShapes(1).Type = wdInlineShapeLockedCanvas Then
MsgBox "wdInlineShapeLockedCanvas"
Exit Sub
ElseIf ActiveWindow.Selection.InlineShapes(1).Type = wdInlineShapeOLEControlObject Then
MsgBox "wdInlineShapeOLEControlObject"
Exit Sub
ElseIf ActiveWindow.Selection.InlineShapes(1).Type = wdInlineShapeOWSAnchor Then
MsgBox "wdInlineShapeOWSAnchor"
Exit Sub
ElseIf ActiveWindow.Selection.InlineShapes(1).Type = wdInlineShapePicture Then 'DOESNT FIND SOME PICTURES PASTED FROM WEB!
MsgBox "wdInlineShapePicture"
Exit Sub
ElseIf ActiveWindow.Selection.InlineShapes(1).Type = wdInlineShapePictureBullet Then
MsgBox "wdInlineShapePictureBullet"
Exit Sub
ElseIf ActiveWindow.Selection.InlineShapes(1).Type = wdInlineShapePictureHorizontalLine Then
MsgBox "wdInlineShapePictureHorizontalLine"
Exit Sub
ElseIf ActiveWindow.Selection.InlineShapes(1).Type = wdInlineShapeScriptAnchor Then
MsgBox "wdInlineShapeScriptAnchor"
Exit Sub
ElseIf ActiveWindow.Selection.InlineShapes(1).Type = wdInlineShapeSmartArt Then
MsgBox "wdInlineShapeSmartArt"
Exit Sub
End If
NO_SHAPE_FOUND:
MsgBox "No floating or inline shape selected!"
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kazimierz Jawor |
| Solution 2 | |
| Solution 3 | cinnamonandgravy |
| Solution 4 | Anton Mukhanin |
| Solution 5 |

