VBA 复选框名称长度限制

标签 vba excel

我只是有一个简单的问题。 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 帮助即可。但是,为了在您的情况下充分利用帮助,请手动尝试更改控件的名称,您将看到如下所示的错误

enter image description here

只需单击“帮助”,它就会带您进入相关的 MSDN 页面(如果您有互联网连接):)

请引用链接Not a legal object name

万一链接失效

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/

相关文章:

excel - 如何编辑此 VBA 代码以接受不同的值?

vba - 将存储的、以管道分隔的字符串转换回日期,并从中删除逗号(小数分隔符)

.net - 如何将 'date lookalike' 文本列导出到 csv

vba - 如何在没有 xmlns/idQ 的情况下将组添加到(VBA)自定义功能区?

php - 使用 PHPExcel 函数将日期和日期时间写入 Excel 中作为文本

vba - 错误 1004 - 此选择在 Range.Insert 上无效

excel - 如何使用 Application.OnTime 在每天设定的时间调用宏,而无需关闭工作簿

mysql - 在 Access VBA 中循环 Access strSQL 中的日期

c# - 从 Excel 中的范围中删除单元格

excel vba内存使用优化