Forms Toolbar Checkbox

Stubby

Board Regular
Joined
Mar 5, 2002
Messages
188
Hi

I have a spreadsheet with various checkboxes from the Forms toolbar added to it. I canget code to run through and find each control however I can't get the code to search for just the checkboxes that have been selected. here's the code i am using

Sub chchk()


'Loop for Form controls.
Set myC = ActiveSheet.Shapes

For Each sh In myC
If sh.Type = msoFormControl Then

If sh.FormControlType = xlCheckBox Then
'**** check if check box selected
If sh.ControlFormat.Checked = True Then
myvar = sh.TopLeftCell.Address
MsgBox myvar
End If
End If
End If
Next sh

End Sub

any help much appreciated
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Something like this
Code:
Sub test()
    Dim resultString As String
    Dim oneShape As Shape
    For Each oneShape In ActiveSheet.Shapes
        With oneShape
        If .Type = msoFormControl Then
            If .FormControlType = xlCheckBox Then
                If .ControlFormat.Value = xlOn Then
                    resultString = resultString & .Name & vbCr
                End If
            End If
        End If
        End With
    Next oneShape
    MsgBox resultString & "are checked."
End Sub
To test a forms check box, test if Shape.ControlFormat.Value = xlOn or xlOff.
But when I try to set a forms checkbox via the .ControlFormat, (e.g. Shape.ControlFormat.Value = xlOn) Excel crashes (Excel2004 bug I presume)
To set Forms checkboxes I use Shape.OLEFormat.Object.Value = xlOn or xlOff.
 
Upvote 0
Something like this
Code:
Sub test()
    Dim resultString As String
    Dim oneShape As Shape
    For Each oneShape In ActiveSheet.Shapes
        With oneShape
        If .Type = msoFormControl Then
            If .FormControlType = xlCheckBox Then
                If .ControlFormat.Value = xlOn Then
                    resultString = resultString & .Name & vbCr
                End If
            End If
        End If
        End With
    Next oneShape
    MsgBox resultString & "are checked."
End Sub
To test a forms check box, test if Shape.ControlFormat.Value = xlOn or xlOff.
But when I try to set a forms checkbox via the .ControlFormat, (e.g. Shape.ControlFormat.Value = xlOn) Excel crashes (Excel2004 bug I presume)
To set Forms checkboxes I use Shape.OLEFormat.Object.Value = xlOn or xlOff.
i'll give it a try. Thanks
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top