Reputation: 1546
i have just simple question. Is here some limit in excel VBA to checkbox name?
i have code like this, and when im using name longer than 33 characters, i have error Unable to set the Name property of the checkbox class (its only a test code)
So is here some way to bypass this?
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
Upvotes: 2
Views: 1540
Reputation: 149315
Whenever you face such kind of limits, simply use the inbuilt office help. However to make the best use of help in your case, manually try to change the name of the control and you will see an error as shown below
Simply click on help and it will take you to the relevant MSDN page in you have internet connectivity :)
Please refer to the link Not a legal object name
In case the link dies
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.
Upvotes: 3