Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel vba形状内部名称/类型_Vba_Excel - Fatal编程技术网

Excel vba形状内部名称/类型

Excel vba形状内部名称/类型,vba,excel,Vba,Excel,我需要删除除命令按钮以外的所有形状。或者只删除椭圆、直线和绘制的直线 Sub deleteShapes() Dim shp As Shape For Each shp In ActiveSheet.Shapes shp.Delete Next shp End Sub 在Jamie Bull中,删除形状: 如果不是(Shp.Type=msoOLEControlObject或Shp.Type=msoFormControl),则Shp.Delete 但我如何才能获得命令按钮类型?还是其他类

我需要删除除命令按钮以外的所有形状。或者只删除椭圆、直线和绘制的直线

Sub deleteShapes()

Dim shp As Shape
For Each shp In ActiveSheet.Shapes

  shp.Delete
Next shp

End Sub
在Jamie Bull中,删除形状:

如果不是(Shp.Type=msoOLEControlObject或Shp.Type=msoFormControl),则Shp.Delete

但我如何才能获得命令按钮类型?还是其他类型的对象?我试过了

Sub testShapes()
    Dim shp As Shape

For Each shp In ActiveSheet.Shapes
    MsgBox (shp.Type)
Next shp

End Sub
但它只给出数字:9,5,1,12。我不知道哪个数字是哪个形状。有没有办法获得内部名称,比如
msoOLEControlObject
,或者至少确保数字1是真正的命令按钮?

类型列表如下: 所有值都在VBA中定义为常量,因此您可以编写

if not shp.Type = msoOLEControlObject then
    shp.Delete
end if
要获取有关您拥有的控制类型的更多信息,请执行以下操作:

Dim sh As Shape
For Each sh In Activesheet.Shapes
    Debug.Print sh.Name, sh.Type

    If sh.Type = msoFormControl Then
        Debug.Print "  msoFormControl:" & sh.FormControlType
    End If

    If sh.Type = msoOLEControlObject Then
        Debug.Print "  msoOLEControlObject: " & TypeName(sh.OLEFormat.Object.Object)
    End If
Next sh
FormControlType如下所示:-所有也被定义为VBA常量

类型列表如下所示: 所有值都在VBA中定义为常量,因此您可以编写

if not shp.Type = msoOLEControlObject then
    shp.Delete
end if
要获取有关您拥有的控制类型的更多信息,请执行以下操作:

Dim sh As Shape
For Each sh In Activesheet.Shapes
    Debug.Print sh.Name, sh.Type

    If sh.Type = msoFormControl Then
        Debug.Print "  msoFormControl:" & sh.FormControlType
    End If

    If sh.Type = msoOLEControlObject Then
        Debug.Print "  msoOLEControlObject: " & TypeName(sh.OLEFormat.Object.Object)
    End If
Next sh

FormControlType如下所示:-所有也被定义为VBA常量

如果您对形状使用默认名称,那么对于表单按钮:

Sub poiuyt()
    Dim shp As Shape

    For Each shp In ActiveSheet.Shapes
        If Left(shp.Name, 6) = "Button" Then
        Else
            shp.Delete
        End If
    Next shp
End Sub
如果按钮是activex,则:

Sub trewq()
    Dim shp As Shape

    For Each shp In ActiveSheet.Shapes
        If Left(shp.Name, 13) = "CommandButton" Then
        Else
            shp.Delete
        End If
    Next shp

End Sub

此方法仅在名称为默认类型时有效。

如果形状使用默认名称,则窗体按钮:

Sub poiuyt()
    Dim shp As Shape

    For Each shp In ActiveSheet.Shapes
        If Left(shp.Name, 6) = "Button" Then
        Else
            shp.Delete
        End If
    Next shp
End Sub
如果按钮是activex,则:

Sub trewq()
    Dim shp As Shape

    For Each shp In ActiveSheet.Shapes
        If Left(shp.Name, 13) = "CommandButton" Then
        Else
            shp.Delete
        End If
    Next shp

End Sub

此方法仅在名称为默认类型时有效。

您也可以在循环中返回名称,然后您就会知道。它们是ActiveX还是Excel表单控件?是的,这很重要。你也可以在循环中返回名称,然后你就会知道。它们是ActiveX还是Excel表单控件?是的,这很重要。