Excel-VBA: Getting the values from Form Controls

后端 未结 6 1775
挽巷
挽巷 2020-12-19 00:22

Embedded in the worksheet sheet1 I have a Form Control combo box named combobox_test and it has selected value x

in addition t

相关标签:
6条回答
  • 2020-12-19 00:58
    putItRng.Rows(1)= ActiveSheet.combobox_test.value
    

    Try:

    activesheet.cells(1,putItRng.column).value=activesheet.combobox_test.value
    

    If it doesnt work then your combobox is not named "Combobox_test"

    0 讨论(0)
  • 2020-12-19 01:01

    As said before the Shape ComboBox has no Value property.

    I use the DrawingObject property of the Shape object to get a CheckBox FormControl object. This CheckBox object can then be used like any other FormControl.

    You should also be able to use the DrawinObject to get the ComboBox objcet form the Shape object.

    If you want to get te selected text then you can try following code snipped:

    Dim sh as Shape
    Dim cB as ComboBox
    For Each sh In ws.Shapes
        If sh.Type = msoFormControl Then
            If TypeOf sh.DrawingObject Is ComboBox Then
                Set cB = sh.DrawingObject
                ... 
                your code for getting the Data from ComboBox
                ...
            End If
        End If
    Next
    
    0 讨论(0)
  • 2020-12-19 01:01

    Thanks been fighting with this this one but this topic gave me an answer. I don't know a difference of method1 or method2 reference type, value can be read using .value|.List attributes. It would be great to have a fully typed obj variable.

    Dim obj As Object
    Set obj = ws.DropDowns("combo1")  ' method 1
    Set obj = ws.Shapes("combo1").ControlFormat  ' method 2
    Debug.Print obj.value & "|" & obj.List(obj.value)  ' 1...n|Text1,Text2,..n
        
    
    0 讨论(0)
  • 2020-12-19 01:14
    ActiveSheet.Shapes("combobox_test").ControlFormat.ListIndex
    
    0 讨论(0)
  • 2020-12-19 01:18
       Sub QuickSelect_Change()
            With ActiveSheet.Shapes("QuickBox")
                MsgBox "My Selected Value " & .ControlFormat.List(.ControlFormat.ListIndex)
            End With
        End Sub
    
    0 讨论(0)
  • 2020-12-19 01:22

    I'm not sure this is what you want, but it's a start. The Shape object doesn't have a Value property, which is the source of the error. There is a DropDown object that is deprecated, but still available.

    Sub ButtonPressed_sample()
    
        Set putitrng = Range("theCells")
        putitrng.Rows(1) = ActiveSheet.DropDowns("combobox_test").value
    
    End Sub
    
    0 讨论(0)
提交回复
热议问题