excel - 如果未选择框架中的选项按钮,如何突出显示框架?
问题描述
我有这段代码来突出显示用户窗体中未填写或未选择的任何可见控件。它可以工作,但即使选择了两个选项按钮中的一个,它仍然会突出显示帧。
Dim ControlsOfInterest As Collection
找到了一个函数来识别框架内的 opt 按钮值:
Function OptionGroupSelectionMade(oneButton As MSForms.OptionButton) As Boolean
Dim oneControl As MSForms.Control
For Each oneControl In Me.Controls
If TypeName(oneControl) = "OptionButton" Then
If oneControl.Parent.Name = oneButton.Parent.Name Then
If oneButton.GroupName = oneControl.GroupName Then
If oneControl.Value Then
OptionGroupSelectionMade = True
Exit For
End If
End If
End If
End If
Next oneControl
End Function
然后其余的代码应该只在它们可见时识别未输入的值
'在初始化
Dim oneControl As MSForms.Control
Dim onePage As MSForms.Page
Set ControlsOfInterest = New Collection
For Each onePage In Me.MultiPage1.Pages
If cmbFundingCategory.Value <> "Req Reduction" Or cmbFundingCategory.Value = "Combo (Unreq'd Dollars + Req Reduction)" Then
Else
For Each oneControl In onePage.Controls
If oneControl.Visible And oneControl.Parent.Visible Then
If oneControl.Name Like "txt*" And oneControl.Visible Then
ControlsOfInterest.Add item:=oneControl, key:=oneControl.Name
ElseIf oneControl.Name Like "opt*" And oneControl.Visible Then
ControlsOfInterest.Add item:=oneControl, key:=oneControl.Name
ElseIf oneControl.Name Like "cmb*" And oneControl.Visible Then
ControlsOfInterest.Add item:=oneControl, key:=oneControl.Name
End If
End If
Next oneControl
End If
Next onePage
遍历帧以检查每个帧以查看选项按钮是否为真?
Private Sub CommandButton1_Click()
Dim colBlankFields As New Collection
Dim oneControl As MSForms.Control
Dim i As Long
Dim strPrompt As String
For Each oneControl In ControlsOfInterest
oneControl.BackColor = vbWhite
If oneControl.Name Like "opt*" Then
If Not OptionGroupSelectionMade(oneControl) Then
oneControl.BackColor = RGB(255, 128, 128)
colBlankFields.Add item:=oneControl, key:=oneControl.Name
strPrompt = strPrompt & vbCr & oneControl.Name & " on page " & oneControl.Parent.Caption
End If
Else
If oneControl.Visible And oneControl.Text = vbNullString Then
oneControl.BackColor = RGB(255, 128, 128)
colBlankFields.Add item:=oneControl, key:=oneControl.Name
strPrompt = strPrompt & vbCr & oneControl.Name & " on page " & oneControl.Parent.Caption
End If
End If
Next oneControl
If colBlankFields.Count <> 0 Then
MsgBox "some controls need values" & vbCr & strPrompt
End If
End Sub
但我仍然在 msgbox 中填充了隐藏字段的值,直到组合框“cmbFundingCategory”应该显示它们
解决方案
推荐阅读
- javascript - 如何在 Vue 类组件中使用 date-fns?
- node.js - 测试函数时替换变量的值
- office-js - 教程中的 Microsoft Office 加载项无响应
- magento2.2 - MISCONF Redis 配置为保存 RDB 快照,但目前无法持久保存在磁盘上。可能修改数据集的命令被禁用
- php - 如何在 FormData 对象中捕获返回值
- algorithm - 如何找到两列之间差异的绝对值之和?
- kubernetes - Helm 更改部署工件的名称
- java - Spring AOP切面不拦截注解的方法
- missing-data - 使用具有 NaN 值的 SMOTE
- java - 等价于 graal.js 脚本引擎中的 Nashorn 的 importPackage