在选择中删除Activex复选框

时间:2016-10-26 13:34:22

标签: excel vba

我试图编写一个宏,删除所选范围内的所有activex复选框。我写了这段代码,但它一直返回“对象不支持此属性或方法”错误。请帮忙。

Dim cbx As OLEObject
Dim rng As Range
Set rng = selection
For Each cbx In ActiveSheet.OLEObjects
    If Not Intersect(rng, cbx.Object.TopLeftCell) Is Nothing Then cbx.Delete
Next

2 个答案:

答案 0 :(得分:1)

这将删除选择中的所有ActiveX复选框:

Sub DeleteActiveXCheckboxes()

Dim Shape As Shape

For Each Shape In ActiveSheet.Shapes
    If Shape.Type = 12 Then
        If Not Intersect(Shape.TopLeftCell, Selection) Is Nothing Then
            Shape.Delete
        End If
    End If
Next Shape

End Sub

答案 1 :(得分:1)

If Not Intersect(rng, cbx.TopLeftCell) Is Nothing Then cbx.Delete
相关问题