使用VBA设置组合框的值

DSG*_*DSG 5 excel vba combobox shapes

我有一个组合框,其中包含指定范围内的 200 多个值,用户可以选择选择这 200 多个值中的任何一个,也可以在组合框中自由键入任何其他值。这很好用。

我的问题是,我无法使用 VBA 代码中的字符串变量中指定的值填充同一组合框。我想做以下事情:

Sub FillInComboBox()
Dim strExample as String

strExample = "Random Text"

Worksheets("Sheet1").Shapes("ComboBox1").Value = strExample 

End Sub
Run Code Online (Sandbox Code Playgroud)

我收到“运行时错误 '438:对象不支持此属性或方法”。我还尝试了上面代码的很多变体,并且在谷歌上搜索了两个小时但没有成功,所以我现在求助于你,作为我让这个工作成功的最后希望。

Har*_*4HR 2

使用以下子程序。

    Sub FillInComboBox()
    Dim strExample As String
        strExample = "Random Text"

        With Sheet1.ComboBox1
            .AddItem strExample
            .AddItem "Second Item"
            .AddItem "Third Item"
        End With
    End Sub
Run Code Online (Sandbox Code Playgroud)