简体   繁体   English

Mac版VBA Excel 2011中复选框的处理方式

[英]How checkboxes are handled in VBA Excel 2011 for Mac

I have searched thoroughly through the Internet and the Stackoverflow site without success. 我已经通过Internet和Stackoverflow网站进行了彻底搜索,但没有成功。 I've been stuck in a problem for a week and I cannot make heads or tails of it. 我被困在一个问题中已经一个星期了,我对此无能为力。

I have been studying VBA and my reference book is giving the following example: 我一直在学习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

Unfortunately this code does not work. 不幸的是,此代码不起作用。 It is supposed to evaluate every embedded boject on the worksheet. 它应该评估工作表上的每个嵌入式项目。 When the code comes across an ActiveX CheckBox, it should determine whether the CheckBox is checked. 当代码遇到ActiveX CheckBox时,应确定是否选中了CheckBox。 At the end of the procedure, a MsgBox will appear, confirming how many (if any) CheckBox were checked and their caption. 在该过程结束时,将出现一个MsgBox,确认选中了多少个CheckBox及其标题。

Can anybody help me with this? 有人可以帮我吗? Even a link would be more than welcome. 甚至一个链接都将受到欢迎。

Thank you in advance for your assistance. 预先感谢您的协助。

You need to amend the if condition to: 您需要将if条件修改为:

= "CheckBox"

You have a space in between which is why. 您之间有一个空格,这就是为什么。

Just to expand (posted that by mobile): 只是为了扩展(通过手机发布):

The TypeName function returns the name of the object and when used in an if condition, needs to be referred to in a case sensitive and correct manor. TypeName函数返回对象的名称,并且在if条件中使用时,需要区分大小写和正确的庄园。 In your case you need to use: 在您的情况下,您需要使用:

If TypeName(xObj.Object) = "CheckBox" Then

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM