简体   繁体   English

Excel VBA组合框锁定属性问题

[英]Excel VBA combobox locked property issue

I'm having an issue with the .locked property when I add a combobox to a sheet. 将组合框添加到工作表时,.locked属性出现问题。 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. 当我进入设计模式并查看按钮的属性时,它仍然显示Locked is True。 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. 感谢您的宝贵时间,我有86个组合框,因此手动将其解锁很麻烦。

-Aaron -Aaron

I did a simple copy+paste of you code, with some modifications so it would work in a brand new, blank workbook: 我对代码进行了简单的复制+粘贴,并进行了一些修改,以便可以在全新的空白工作簿中使用:

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

The above code worked fine for me, in developer mode it says that the locked property is false. 上面的代码对我来说很好用,在开发人员模式下它说locked属性为false。
I am using Microsoft Excel 2007. 我正在使用Microsoft Excel 2007。
It could be something to do with your i variable, since the only difference is that I just used a static range of N1 and it worked fine. 这可能与您的i变量有关,因为唯一的区别是我只使用了静态范围N1 ,并且工作正常。 Though I'm not sure how the sizing of it could cause it to not lock. 虽然我不确定它的大小如何导致它无法锁定。

Try copying and pasting my code yourself and see what it spits out. 尝试自己复制和粘贴我的代码,看看它吐出了什么。

Try this AFTER adding all your comboboxes on Sheet1: 在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

Hope this helps, 希望这可以帮助,
kpark park

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM