简体   繁体   English

在Excel 2010中隐藏或取消隐藏VBA的控件是正确的吗?

[英]It is correct for hide or unhide a control by VBA in Excel 2010?

I have a sheet named "MainSheet" in a Workbook in Excel 2010. 我在Excel 2010的工作簿中有一个名为“MainSheet”的工作表。

this sheet included an activeX control named "OptionButton1". 此表包含名为“OptionButton1”的activeX控件。 when the cell's value of "C18" is "2" then this control should be hide. 当单元格的“C18”值为“2”时,该控件应该隐藏。

I wrote below code but does not work. 我写下面的代码,但不起作用。

► a more question: can I have three activeX (Radio Button) related to one cell with three different value like radio button in form control? ►更多问题:我可以将三个与一个单元格相关的activeX(单选按钮)与三个不同的值相关联,例如表单控件中的单选按钮吗?

Any advice is appreciated. 任何建议表示赞赏。 :) :)

Sub MS_Method()

If Range("C18").Value = 2 Then

    ActiveSheet.MainSheet("OptionButton1").Visible = False

ElseIf Range("C18").Value = 1 Then

    ActiveSheet.MainSheet("OptionButton1").Visible = True

End If

End Sub

Assuming your ActiveX OptionButton is Named "OptionButton1", the code below (tested) will work: 假设您的ActiveX OptionButton命名为“OptionButton1”,下面的代码(已测试)将起作用:

Option Explicit

Sub MS_Method()

Dim Sht                 As Worksheet

' modify "MainSheet" to your sheet name (where you have your OptionButton)
Set Sht = ThisWorkbook.Sheets("MainSheet")

If Range("C18").Value = 2 Then
    Sht.OLEObjects("OptionButton1").Visible = False
ElseIf Range("C18").Value = 1 Then
    Sht.OLEObjects("OptionButton1").Visible = True
End If

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM