ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Trigger an event on Checkbox change (https://www.excelbanter.com/excel-programming/308692-re-trigger-event-checkbox-change.html)

James Geniti

Trigger an event on Checkbox change
 

Thanks for the responses everyone, but now I have a whole new problem. I
have created a function that will allow me create a checkbox in any
given cell. Because I just found out that checking the checkbox will not
trigger the change event on the worksheet I will need to attach a
general macro to all the checkboxes I create that have a name that
begins with "labor". For some reason when I run this code I get a run
time error that says "Unable to set the OnAction property of the
OLEObject class". Am I missing something or is there a better way to do
this?

'This function will create a checkbox when given a cell range, name for
the check box
'and a cell to link the value to
Function Create_Checkbox(ByVal CurrCell As String, _
ByVal ListName As String, _
ByVal CellLink As String)

Dim Obj As Object
Dim CBox As Object
Dim OldZoom As Integer


OldZoom = ActiveWindow.zoom
ActiveWindow.zoom = 100

Set Obj = ActiveSheet.OLEObjects.Add(classtype:="Forms.Check Box.1", _
Left:=Range(CurrCell).Left + (Range(CurrCell).width / 2) -
6.5, _
Top:=Range(CurrCell).Top + (Range(CurrCell).height / 2) - 5,
_
width:=11, height:=11)

Set CBox = Obj.Object
CBox.Caption = ""

With Obj
.Name = ListName
.LinkedCell = CellLink
If Left(ListName, 5) = "labor" Then
.OnAction = "UpdateLabor"
End If
End With

If Range(CellLink).Value = Empty Then
Range(CellLink).Value = "FALSE"
End If
Range("ObjectCounter").Value = Range("ObjectCounter").Value + 1
ActiveWindow.zoom = OldZoom
End Function


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


All times are GMT +1. The time now is 05:10 PM.

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