Hi Bruce,
Here are two of the many renaming options:
Sub CheckBoxRenamingScenarios()
'NOTE: There will be a runtime error if "CheckBox1" or "ChecBox2" does not exist
Debug.Print ActiveSheet.OLEObjects(1).Name
Debug.Print ActiveSheet.OLEObjects("CheckBox1").Name
ActiveSheet.OLEObjects(1).Name = "cb01"
Debug.Print ActiveSheet.OLEObjects(1).Name
Debug.Print
Debug.Print ActiveSheet.OLEObjects(2).Name
Debug.Print ActiveSheet.OLEObjects("CheckBox2").Name
ActiveSheet.OLEObjects("CheckBox2").Name = "cb02"
Debug.Print ActiveSheet.OLEObjects("cb02").Name
Debug.Print ActiveSheet.OLEObjects(2).Name
End Sub
See the attached file that works with Active X checkboxes. It doesn't specifically answer your question, but may provide you with tools to get the job done.
Here are a few excerpts from the file:
Sub AddActiveXCheckBoxToActiveCell()
Dim sCell As String
sCell = ActiveCell.Address
Call AddActiveXCheckBox(sCell)
End Sub
Sub AddActiveXCheckBox(sCell As String)
Const xCheckBoxHeight = 12
Const xCheckBoxWidth = 12
Dim r As Range
Dim xHeight As Double
Dim xLeft As Double
Dim xTop As Double
Dim xWidth As Double
Set r = Range(sCell)
'Get the dimensions of the active cell
xHeight = r.Height
xLeft = r.Left
xTop = r.Top
xWidth = r.Width
'Calculate starting point for the new 'Active X Check Box'
xLeft = xLeft + (xWidth - xCheckBoxWidth) / 2#
xTop = xTop + (xHeight - xCheckBoxHeight) / 2#
'Add the 'Active X' Check Box
'Link the 'Check Box' to the underlying Cell
With ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1", _
Left:=xLeft, _
Top:=xTop, _
Width:=xCheckBoxWidth, _
Height:=xCheckBoxHeight)
.Object.Caption = ""
.LinkedCell = r.Address
.Object.Value = False
End With
'Hide the contents of the Underlying Cell
r.NumberFormat = ";;;"
End Sub
Lewis
Bookmarks