无法选择组合框。

3

我有一个名为“Facility”的组合框,已添加到Excel 2010工作表中作为表单控件。我还有一个名为“AdjustmentsAmount”的模块,在表单按钮单击时运行以下方法。我尝试了几种访问表单控件的方法,但都没有成功,也在下面列出了。有谁可以帮我解决这个问题吗?

代码

'Clears all run specifications
Sub clearRunSpecs_click()
    Dim resp As String
    resp = MsgBox("This will clear all run specifications. Are you sure you want to continue?", vbYesNo)
    If (resp = vbYes) Then
        Worksheets("AdjustmentsAmount").Unprotect "pass"
        Range("D3").Clear
        Range("D3").Interior.Color = RGB(235, 241, 222)
        Range("D3").BorderAround LineStyle:=XlLineStyle.xlContinuous, Weight:=xlMedium, ColorIndex:=xlColorIndexAutomatic, Color:=RGB(0, 0, 0)
        Range("D3").Locked = False
        Range("D4").Clear
        Range("D4").Interior.Color = RGB(235, 241, 222)
        Range("D4").BorderAround LineStyle:=XlLineStyle.xlContinuous, Weight:=xlMedium, ColorIndex:=xlColorIndexAutomatic, Color:=RGB(0, 0, 0)
        Range("D4").Locked = False
        Range("B4").Clear
        Range("B4").Interior.Color = RGB(235, 241, 222)
        Range("B4").BorderAround LineStyle:=XlLineStyle.xlContinuous, Weight:=xlMedium, ColorIndex:=xlColorIndexAutomatic, Color:=RGB(0, 0, 0)
        Range("B4").Locked = False
        Range("A17:D22").Clear
        Range("A17:D22").Merge
        Range("A17:D22").Interior.Color = RGB(235, 241, 222)
        Range("A17:D22").BorderAround LineStyle:=XlLineStyle.xlContinuous, Weight:=xlMedium, ColorIndex:=xlColorIndexAutomatic, Color:=RGB(0, 0, 0)
        Range("A17:D22").VerticalAlignment = xlTop
        Range("A17:D22").Locked = False
        ActiveSheet.Shapes("Facility").ListIndex = -1
        ActiveSheet.CheckBoxes("ZeroBalance").Value = xlOff
        ActiveSheet.CheckBoxes("Balance<Adj").Value = xlOff
        ActiveSheet.CheckBoxes("Balance=Adj").Value = xlOff
        Worksheets("AdjustmentsAmount").Protect "pass"
    End If
End Sub

尝试的方法

ActiveSheet.Shapes("Facility")
ActiveSheet.Facility
ActiveSheet.ListBoxes("Facility")
Application.Facility

我使用ActiveSheet.CheckBoxes("NAME")成功地访问了复选框,但是我似乎无法掌握组合框。

2个回答

1

有点隐藏 - 您可以像这样访问列表框或组合框:

Debug.Print ActiveSheet.Shapes("Facility").OLEFormat.Object.Value

1
我已经将空行设置为ListIndex1,并使用了以下代码:
ActiveSheet.Shapes("Facility").ControlFormat.ListIndex = 1

访问它。我假设这就是你需要的?


我希望该框重置为空状态。我以为这是listindex = -1(因为我之前在一个网站上看到过)。但是这是不允许的。有什么想法吗? - steventnorris

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接