本文介绍了VBA - 框架中的选项按钮的值(在Excel表格中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我试图检查我的选项按钮是否被填充。到目前为止,我已经做了以下工作:

  Sub SX_EXTERNE()

Dim Ws As Worksheet
Dim ConBut As Shape
Dim Answer As String

设置Ws = ThisWorkbook.Sheets(Externe)

对于每个ConBut在Ws.Shapes
如果ConBut.Type = msoFormControl然后
如果ConBut.FormControlType = xlOptionButton然后
如果ConBut.ControlFormat.Value = xlOn然后
答案= ConBut.Name
结束If
结束如果
结束如果
下一个ConBut

MsgBox答案

结束Sub
/ pre>

我的问题是我不知道如何仅在选定的框架中检查(例如Conges_generaux):









你能给我一个提示吗?我已经看过很多关于这个问题的主题,但是很多人都对待ActiveXControls ...我甚至不了解这个区别。



谢谢

解决方案

这是一个快速的方法

  Sub Sample )
Dim optBtn As OptionButton

对于每个optBtn在ActiveSheet.OptionButtons
如果optBtn.Value = 1然后
Debug.Print optBtn.Name
调试。打印optBtn.GroupBox.Name
结束如果
下一个
结束子

所以在你的代码更改 Dim ConBut As Shape to Dim ConBut As OptionButton 。请随意进行相关检查并将其存储在相关的答案中。变量:)


I'm having problems with shapes, frames and option buttons... I'm a total newbie, I've never used them. I just put several option buttons on an Excel sheet (Using the FORM toolbox).

I'm trying to check whether my optionbutton is filled or not. So far, I've done the following :

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

My problem is I do not know how to check only in a selected frame (i.e. "Conges_generaux" for my example):

Could you please give me a hint? I've seen many subjects about that but many of them treat of ActiveXControls... I don't even know the difference.

Thanks

解决方案

Here is a quick way

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

So in your code change Dim ConBut As Shape to Dim ConBut As OptionButton. Feel free to put relevant checks and store it in the relevant answer variable :)

这篇关于VBA - 框架中的选项按钮的值(在Excel表格中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 11:10