我只是有一个简单的问题。 Excel VBA 对复选框名称有一些限制吗?
我有这样的代码,当我使用超过 33 个字符的名称时,出现错误 Unable to set the Name property of the checkbox class (its only a test code)
那么有什么方法可以绕过这个吗?
Sub createTestBox()
Dim shimSheet As Worksheet
Set shimSheet = Sheets("ShimSheet")
Dim chkbox As checkBox
Dim i As Long
Dim name As String
name = ""
For i = 1 To 50
name = name & "a"
With shimSheet.Cells(12 + i, 3)
shimSheet.CheckBoxes.Add(.Left, .Top, .Width, .Height).name = name
shimSheet.CheckBoxes(name).Delete
End With
Next i
End Sub
最佳答案
每当您遇到此类限制时,只需使用内置的 Office 帮助即可。但是,为了在您的情况下充分利用帮助,请手动尝试更改控件的名称,您将看到如下所示的错误
只需单击“帮助”,它就会带您进入相关的 MSDN 页面(如果您有互联网连接):)
万一链接失效
Not a legal object name: 'item
Office 2013 and later Other Versions
Form and control names must start with a letter and can be a maximum of 40 characters — including letters, numbers, and underscores (_). Note that the Name property of a form or control is different from the Label properties — Caption, Text, and Value — that label or display the contents of a control at run time. These properties can be restricted keywords, can begin with a number, and can contain nonalphanumeric characters.
关于VBA 复选框名称长度限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39617002/