Search code examples
excelvbacomboboxlockedcommandbutton

Excel VBA combobox locked property issue


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


Solution

  • 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