Question

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

Was it helpful?

Solution 2

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

OTHER TIPS

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.
I am using 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. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top