Trouble with checkboxes

NewBoard

New Member
Joined
Apr 25, 2017
Messages
2
Hello, I am trying to create a macro that will print the selected sheets out of a workbook. The first worksheet has a set of Checkboxes that all follow the naming convention "CheckBoxX" where X is the number of that checkbox. What I'd like the code to do, is run through each of these checkboxes, see if it's checked, then select that corresponding worksheet if it is checked. However, I'm getting an error "Object doesn't support this property or method".

Here's my code:
Code:
Option Explicit


Sub Button14_Click()
    Dim count As Integer
    Dim checkNumber As String
    
    For count = 1 To ThisWorkbook.Worksheets.count
        checkNumber = "CheckBox" & count
        If Sheets("Print").Shapes(checkNumber).OLEFormat.Object.Value = True Then
            Worksheets(count + 1).Select (False)
        End If
    Next count
    
    ActiveWindow.SelectedSheets.PrintOut
    
End Sub

The debug always flags the line with the if statement.

I have also tried this as my if statement:
Code:
If Sheets("Print").Shapes(checkNumber).ControlFormat.Value = 1 Then
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
For an ActiveX checkbox, try...

Code:
If Sheets("Print").Shapes("CheckBox1").OLEFormat.Object[COLOR=#ff0000].Object[/COLOR].Value = True Then

Hope this helps!
 
Upvote 0
For an ActiveX checkbox, try...

Code:
If Sheets("Print").Shapes("CheckBox1").OLEFormat.Object[COLOR=#ff0000].Object[/COLOR].Value = True Then

Hope this helps!

This did it! Thank you very much! Any idea why you have to pass the Object function twice?
 
Upvote 0
The first one returns the container or OleObject itself, while the second one returns the CheckBox.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,331
Members
449,077
Latest member
jmsotelo

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