我已经通过Internet和Stackoverflow网站彻底搜索但没有成功 . 我已经陷入了一个问题一个星期,我无法做出正面或反面 .
我一直在研究VBA,我的参考书给出了以下例子:
Private Sub CommandButtons()
Dim intcounter As Integer, xObj As OLEObject
Dim strObj As String
intcounter = 0
strObj = ""
For Each xObj In ActiveSheet.OLEObjects
If TypeName(xObj.Object) = "CheckBox" Then
If xObj.Object.Value = True Then
intcounter = intcounter + 1
strObj = strObj & xObj.Object.Caption & Chr(10)
End If
End If
Next xObj
If intcounter = 0 Then
MsgBox "There were no CheckBoxes selected", , "No Sport"
Else
MsgBox _
"you selected" & intcounter & "checkboxes:" _
& vbCrLf & vbCrLf & _
strObj, , "Here is what you checked"
End If
End Sub
不幸的是,这段代码不起作用 . 它应该评估工作表上的每个嵌入式项目 . 当代码遇到ActiveX CheckBox时,它应该确定是否选中了CheckBox . 在程序结束时,将出现一个MsgBox,确认检查了多少(如果有)CheckBox及其 Headers .
任何人都可以帮我吗?即使是链接也非常受欢迎 .
提前感谢您的帮助 .
1 回答
您需要将if条件修改为:
你之间有一个空间,这就是原因 .
只是为了扩展(通过手机发布):
TypeName
函数返回对象的名称,当在if条件中使用时,需要在区分大小写且正确的庄园中引用 . 在您的情况下,您需要使用: