6

在 Excel 中,我们在左上角有“名称框”,但我找不到在 Word 中检索形状名称的方法。我怎么做?

4

5 回答 5

9

MS Word 中有两种形状 -InlineShapesShapes. 使用一些 VBA 代码很容易检查形状对象的名称:

  1. 选择形状
  2. 按 Alt+F11 打开 VBA 编辑器
  3. 在即时窗口中执行以下代码:? Selection.ShapeRange.Name
  4. 结果,您获得了形状的名称。

InlineShape没有 name 属性,因此在提升您InlineShapeShape类型对象之前,您无法检查它的名称。

于 2013-07-16T15:22:29.283 回答
8

Microsoft Word 2010 及更高版本

Microsoft Word 2010( 2010,20132016) 开始, 中包含一个“选择窗格” Microsoft Word。在选择窗格中列出并命名了 Microsoft WordInlineShapes以及它们。Shapes

您可以Selection Pane在下面的菜单中找到

  1. “主页”选项卡
  2. “编辑”组
  3. “选择”按钮
  4. “选择窗格……”

Microsoft Word 选择窗格


2010 年之前的 Microsoft Word 版本

对于较旧的 Microsoft Word ( 2003, 2007) 版本,请使用 VBA 方法 ( ?Selection.ShapeRange.Name),因为 Kazimierz Jawor 作为此问题的另一个答案发布:https ://stackoverflow.com/a/17680650/1306012

  1. 选择形状
  2. 按 Alt+F11 打开 VBA 编辑器
  3. 按 Ctrl+G 打开即时窗口
  4. 在即时窗口中键入?Selection.ShapeRange.Name以获取形状名称
于 2015-09-03T11:25:23.137 回答
0

最方便的方法是创建一个宏按钮,该按钮可从您的选项卡(例如,主页、插入等)访问。这样,您只需单击形状,单击宏按钮,然后瞧 - 形状名称显示在消息框(弹出窗口)中。

使用以下代码:

MsgBox ActiveWindow.Selection.ShapeRange(1).name
于 2016-07-01T15:25:49.813 回答
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
于 2017-02-04T20:26:51.307 回答
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
于 2021-03-21T04:27:56.797 回答