0

I'm having an issue with the .locked property when I add a combobox to a sheet. I'm using the following code:

    Set cBox = Sheet1.OLEObjects.Add(ClassType:="Forms.ComboBox.1")
        With cBox
            .Left = Sheet1.Range("N" & i).Left
            .Top = Sheet1.Range("N" & i).Top
            .Width = Sheet1.Range("N" & i).Width
            .Height = Sheet1.Range("N" & i).Height
            .ListFillRange = "Sheet3!$A1:$A3"
            .Locked = False
        End With

When I enter design mode and look at the properties of the button, it shows Locked being True still. Is there something incorrect with how I'm editing the property?

Thanks for your time, I have 86 comboboxes, so manually unlocking them would be tedious.

-Aaron

4

2 回答 2

1

我对您的代码进行了简单的复制+粘贴,并进行了一些修改,以便它可以在全新的空白工作簿中使用:

Option Explicit

Sub testCode()
    Dim cBox As Object
    Set cBox = Sheet1.OLEObjects.Add(ClassType:="Forms.ComboBox.1")
        With cBox
            .Left = Sheet1.Range("N1").Left
            .Top = Sheet1.Range("N1").Top
            .width = Sheet1.Range("N1").width
            .height = Sheet1.Range("N1").height
            .ListFillRange = "Sheet3!$A1:$A3"
            .Locked = False
        End With
End Sub

上面的代码对我来说很好,在开发者模式下它说锁定的属性是假的。
我正在使用 Microsoft Excel 2007。
这可能与您的i变量有关,因为唯一的区别是我只使用了一个静态范围N1并且它工作正常。虽然我不确定它的大小如何导致它无法锁定。

尝试自己复制和粘贴我的代码,看看它会吐出什么。

于 2013-08-21T16:26:24.140 回答
0

在 Sheet1 上添加所有组合框后尝试此操作:

Sub a()
    Dim obj As Shape

    For Each obj In Sheet1.Shapes
        'If obj type is 12
        If obj.Type = 12 Then
            obj.Locked = False
        End If
    Next obj
End Sub

希望这会有所帮助,
kpark

于 2013-08-21T16:24:17.757 回答