ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   checkbox linked to a cell (https://www.excelbanter.com/excel-programming/377063-checkbox-linked-cell.html)

Greg[_34_]

checkbox linked to a cell
 
Hello,
I am programatically trying to add a checkbox.
but it looks like you have to give pixal locations

ActiveSheet.OLEObjects.Add(ClassType:="Forms.Check Box.1", Link:=False, _
DisplayAsIcon:=False, Left:=111.75, Top:=197.25, Width:=85.5, Height
_
:=21.75).Select


is there a way to add a checkbox and give the cell row / column?



Dave Peterson

checkbox linked to a cell
 
One way:

Option Explicit
Sub testme()

Dim myCell As Range
Dim OLEObj As OLEObject

Set myCell = ActiveSheet.Range("b3")

With myCell
Set OLEObj = .Parent.OLEObjects.Add(ClassType:="Forms.CheckBox. 1", _
Link:=False, DisplayAsIcon:=False, _
Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
End With

End Sub



Greg wrote:

Hello,
I am programatically trying to add a checkbox.
but it looks like you have to give pixal locations

ActiveSheet.OLEObjects.Add(ClassType:="Forms.Check Box.1", Link:=False, _
DisplayAsIcon:=False, Left:=111.75, Top:=197.25, Width:=85.5, Height
_
:=21.75).Select

is there a way to add a checkbox and give the cell row / column?


--

Dave Peterson


All times are GMT +1. The time now is 03:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com