VBA – 框架中的选项button的值(在Excel工作表内)

我有形状,框架和选项button的问题…我是一个总新手,我从来没有使用过它们。 我只是在Excel工作表上放置了几个选项button(使用FORM工具箱)。

我试图检查我的optionbutton是否填充。 到目前为止,我已经完成了以下工作:

Sub SX_EXTERNE() Dim Ws As Worksheet Dim ConBut As Shape Dim Answer As String Set Ws = ThisWorkbook.Sheets("Externe") For Each ConBut In Ws.Shapes If ConBut.Type = msoFormControl Then If ConBut.FormControlType = xlOptionButton Then If ConBut.ControlFormat.Value = xlOn Then Answer = ConBut.Name End If End If End If Next ConBut MsgBox Answer End Sub 

我的问题是我不知道如何检查只在选定的框架(即“Conges_generaux”为我的例子):

在这里输入图像说明

在这里输入图像说明

在这里输入图像说明

你能给我一个提示吗? 我见过很多关于这个主题的文章,但是其中很多人都对待ActiveXControls …我甚至不知道它们之间的区别。

谢谢

这是一个快速的方法

 Sub Sample() Dim optBtn As OptionButton For Each optBtn In ActiveSheet.OptionButtons If optBtn.Value = 1 Then Debug.Print optBtn.Name Debug.Print optBtn.GroupBox.Name End If Next End Sub 

所以在你的代码Dim ConBut As Shape改为Dim ConBut As OptionButton 。 随意把相关的检查,并将其存储在相关的answervariables:)