VBA - 框架中选项按钮的值(在 Excel sheet 内)
VBA - Value of an option button in a frame (within an Excel sheet)
我在形状、框架和选项按钮方面遇到问题...我是个新手,我从未使用过它们。我只是在 Excel sheet 上放置了几个选项按钮(使用 FORM 工具箱)。
我正在尝试检查我的选项按钮是否已填充。到目前为止,我已经完成了以下工作:
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
。随意进行相关检查并将其存储在相关的 answer
变量中:)
我在形状、框架和选项按钮方面遇到问题...我是个新手,我从未使用过它们。我只是在 Excel sheet 上放置了几个选项按钮(使用 FORM 工具箱)。
我正在尝试检查我的选项按钮是否已填充。到目前为止,我已经完成了以下工作:
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
。随意进行相关检查并将其存储在相关的 answer
变量中:)