vba - Excel - 返回所选选项按钮的标题

标签 vba excel userform

这可能是一个愚蠢的问题,但答案很简单,但在用户表单方面我是一个真正的新手。

我的“Frame 3”有 5 个不同的选项按钮(Dest1、Dest2、Dest3、Dest4、Dest5) 选择选项后,所选选项的标题值存储在哪里?我如何使用 vba 访问它。

谢谢你, 乔什

最佳答案

这只是您可以使用的一些示例代码。将选项按钮添加到组中,然后您就可以从那里开始。我使用了组,因为您有多个框架,您可以根据组进行检查,并且有多个组,然后检查为每​​个组选择了哪个。

Private Sub CommandButton1_Click()
     Dim x As Control

     ' Loop through ALL the controls on the UserForm.
     For Each x In Me.Controls
         ' Check to see if "Option" is in the Name of each control.
         If InStr(x.Name, "Option") Then
             ' Check Group name.
             If x.GroupName = "Grp1" Then
                 ' Check the status of the OptionButton.
                 If x.Value = True Then
                     MsgBox x.Caption
                     Exit For
                 End If
             End If
         End If
     Next
End Sub

关于vba - Excel - 返回所选选项按钮的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21434156/

相关文章:

vba - 在 VBA 中在单元格之间移动图像

.net - Excel 中的 WinForms (2002) 和附加组件

excel - 将宏对话框留在原处

events - Excel VBA - 更新组合框时暂停事件

VBA - 正确销毁无模式用户窗体实例

vba - 从范围复制并过去在另一张工作表中的下一个空单元格中

Excel:在 VBA 中使用命名 Range.NumberFormat: "General"与 "Standard"

vba - 从 VBA 发送数据到 AS400(运行时错误 249)

excel - Excel 中的 VBA 忽略选择

api - 断开 VBA 用户窗体与父应用程序的连接