Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 从单选按钮组捕获值_Vba_Excel_Radio Button - Fatal编程技术网

Vba 从单选按钮组捕获值

Vba 从单选按钮组捕获值,vba,excel,radio-button,Vba,Excel,Radio Button,我试图捕获存储在单选按钮组中的选定值。例如,我有两个单选按钮(没有特定的命名约定)与组名“1”组合在一起。我想知道是否有一种方法可以在不必为实际单选按钮本身专门做if-elseif语句的情况下获得选择的选项 理想情况下,我希望代码能够说查看这个optiongroup,检索文本文件的值并移动到下一个单选按钮组 我正在创建一个调查,需要将调查结果捕获到一个.txt文件中 谢谢。我想您必须测试每个单选按钮控件项的值。该组仅确保在该组中选择一个(或零个)无线电选项。请记住,可能没有选择任何选项。我没有专

我试图捕获存储在单选按钮组中的选定值。例如,我有两个单选按钮(没有特定的命名约定)与组名“1”组合在一起。我想知道是否有一种方法可以在不必为实际单选按钮本身专门做if-elseif语句的情况下获得选择的选项

理想情况下,我希望代码能够说查看这个optiongroup,检索文本文件的值并移动到下一个单选按钮组

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


谢谢。

我想您必须测试每个单选按钮控件项的值。该组仅确保在该组中选择一个(或零个)无线电选项。请记住,可能没有选择任何选项。

我没有专门尝试使用组,但以下是如何在用户窗体上使用帧(据我所知,帧的工作方式与使用分离选项的组类似)

  • 本例的用户表单名称为“UF
  • 包含多个选项的1st帧的名称为“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
    

当我在互联网上搜索时,我尝试过使用类似的方法:选择案例选项组1。值案例1 MsgBox“您选择了选项1”案例2 MsgBox“您选择了选项2”结束选择我还尝试了其他一些代码,但我认为我没有找到任何正确引用该组的代码。