【问题标题】:Capture Value From Radio Button Group从单选按钮组捕获值
【发布时间】:2014-03-27 12:24:41
【问题描述】:

我正在尝试捕获存储在单选按钮组中的选定值。例如,我有两个单选按钮(没有特定的命名约定)与组名“1”组合在一起。我想知道是否有一种方法可以让您选择哪个选项,而无需专门为实际的单选按钮本身执行 IF elseif 语句。

理想情况下,我希望代码能够查看此选项组,检索文本文件的值并移至下一个单选按钮组。

我正在创建一项调查,其中需要将结果捕获到 .txt 文件中。

谢谢。

【问题讨论】:

  • 我在网上搜索时尝试过使用类似的东西: Select Case OptionGroup1.Value Case 1 MsgBox "你选择了选项 1" Case 2 MsgBox "你选择了选项 2" End Select Also我也尝试了其他一些代码,但我认为我没有真正找到正确引用该组的任何内容。

标签: vba excel radio-button


【解决方案1】:

我认为您将不得不测试每个单选按钮控件项的值。该组仅确保在该组中选择了一个(或零个)单选选项。请记住,可能没有选择任何选项。

【讨论】:

    【解决方案2】:

    我没有专门尝试过使用组,但这里是你如何在用户窗体上使用框架(据我了解框架与具有隔离选项的组类似)的方法。

    • 此示例的用户表单名称为 'UF'
    • 包含多个选项的第一个帧的名称是'Frame1'
    • 包含多个选项的 2nd 框架的名称是“Frame2

      'get the option selected within Frame1
      Dim opt as Control
      For Each opt in UF.Frame1.Controls
         If TypeName(opt) = "OptionButton" And opt = True Then
            x = MsgBox(opt.Caption) 'Outputs Caption of Selected Option in Frame1
         End If
      Next
      '----------------------------------------
      '----------------------------------------
      
      'and this would get the option selected within Frame2
      Dim opt as Control
      For Each opt in UF.Frame2.Controls
         If TypeName(opt) = "OptionButton" And opt = True Then
            x = MsgBox(opt.Caption) 'Outputs Caption of Selected Option in Frame2
         End If
      Next
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-06
      • 1970-01-01
      • 2011-03-14
      • 2011-03-28
      • 1970-01-01
      • 1970-01-01
      • 2013-09-04
      • 1970-01-01
      相关资源
      最近更新 更多