在Excel中,我们在左上角有“名称框”,但我找不到在Word中检索形状名称的方法。我该怎么做?
答案 0 :(得分:8)
MS Word中有两种形状 - InlineShapes
和Shapes
。使用一些VBA代码检查形状对象的名称非常容易:
? Selection.ShapeRange.Name
InlineShape
没有名称属性,因此在将InlineShape
提升为Shape
类型对象之前,您无法检查其名称。
答案 1 :(得分:6)
Microsoft Word 2010
以后
从Microsoft Word 2010
开始(2010
,2013
和2016
),有一个"选择窗格"包含在Microsoft Word
中。
在选择窗格中,列出并命名了Microsoft Word InlineShapes
以及Shapes
。
您可以在
下的菜单中找到Selection Pane
较早Microsoft Word
个版本
对于旧的Microsoft Word(2003
,2007
)版本使用VBA方法,因为Kazimierz Jawor发布了此问题的另一个答案:https://stackoverflow.com/a/17680650/1306012
答案 2 :(得分:0)
最方便的方法是创建一个宏按钮,可以从标签中访问(例如,Home,Insert等)。这样,您只需单击形状,单击宏按钮,然后瞧 - 形状名称将显示在消息框中(弹出窗口)。
使用以下代码:
MsgBox ActiveWindow.Selection.ShapeRange(1).name
答案 3 :(得分:0)
正确答案,我希望)))
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
答案 4 :(得分:0)
Word 2007 适用于图片,其余未测试
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