View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default Macro for checkbox generation

Dim myCBX As Object
Dim myCell As Range

With ActiveSheet
'CheckBoxes.Delete 'nice for setting up
For Each myCell In ActiveSheet.Range("P13:P50")
With myCell
Set myCBX =
..Parent.OLEObjects.Add(ClassType:="Forms.CheckBox .1", _
Link:=False, _
DisplayAsIcon:=False, _
Left:=.Left, _
Top:=.Top, _
Width:=.Width, _
Height:=.Height)
End With

With ActiveSheet.OLEObjects("CheckBox1") 'myCBX
.Placement = xlMoveAndSize
.LinkedCell = myCell.Address(external:=True)
.Object.Caption = ""
.Name = "CBX_" & myCell.Address(0, 0)
End With

myCell.NumberFormat = ";;;"

Next myCell
End With


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"rmcveigh" wrote in
message ...

Thanks Tom for the response.

It doesn't seem to be working (is this because we used checkboxes from
the form toolbox?). It won't even allow you to manually select the
'moveandsize' option for the boxes.

So we tried this, hoping to switch over to the controls checkbox (am I
making sense?):

Option Explicit
Sub RunOnce()

Dim myCBX As CheckBox
Dim myCell As Range

With ActiveSheet
CheckBoxes.Delete 'nice for setting up
For Each myCell In ActiveSheet.Range("P13:P503").Cells
With myCell
Set myCBX = .Parent.OLEObjects.Add(ClassType:="Forms.CheckBox. 1",
Link:=False, _
DisplayAsIcon:=False, Left:=.Left, Top:=.Top, _
Width:=.Width, Height:=.Height).Select
With myCBX
Placement = xlMoveAndSize
LinkedCell = myCell.Address(external:=True)
Caption = ""
Name = "CBX_" & myCell.Address(0, 0)
End With


NumberFormat = ";;;"
End With

Next myCell
End With
End Sub


--
rmcveigh
------------------------------------------------------------------------
rmcveigh's Profile:

http://www.excelforum.com/member.php...o&userid=37353
View this thread: http://www.excelforum.com/showthread...hreadid=571452