error when executing multiple checkboxes to run macros for printing

LoneStarPiper

New Member
Joined
Mar 29, 2019
Messages
15
Hello all, I'm not terribly experienced in macros, but I'm learning as I go. Any help is appreciated. I have a workbook with many worksheets inside it. From a master worksheet, I'd like my staff to be able to select which worksheets to print by selecting them with checkboxes. I have a macro written that is trying to say "IF a checkbox is selected, run a print macro (already written)". I continue to get the error " Run-time error '1004': Unable to get the CheckBoxes property of the Worksheet class" and when I selected "debug" it normally takes me to the next line after the page I printed. Any ideas?

Sub PrintSelectedSheets()
'Installer Copy Checkbox values are 0 (false), 1 (true), 2 (changed or grey)
If ActiveSheet.CheckBoxes("chk3installcopies").Value = 1 Then
Call InstallerCopyWPrint
End If
'MISC Checkbox values are 0 (false), 1 (true), 2 (changed or grey)
If ActiveSheet.CheckBoxes("chkMISC").Value = 1 Then
Call MISC_PrepareForPrint
Call MISC_Print
End If
'Job Notes Checkbox values are 0 (false), 1 (true), 2 (changed or grey)
If ActiveSheet.CheckBoxes("JobNotesBox").Value = 1 Then
Call JobNotes_Print
End If
'ALUMINUM Checkbox values are 0 (false), 1 (true), 2 (changed or grey)
If ActiveSheet.CheckBoxes("chkAlum").Value = 1 Then
Call ALUM_PrepareForPrint
Call ALUM_Print
End If
'Galvalume Checkbox values are 0 (false), 1 (true), 2 (changed or grey)
If ActiveSheet.CheckBoxes("chkGalv").Value = 1 Then
Call GALV_PrepareForPrint
Call GALV_Print
End If
'Copper Checkbox values are 0 (false), 1 (true), 2 (changed or grey)
If ActiveSheet.CheckBoxes("chkCopper").Value = 1 Then
Call COPPER_PrepareForPrint
Call COPPER_Print
End If
'ALUM HALF Checkbox values are 0 (false), 1 (true), 2 (changed or grey)
If ActiveSheet.CheckBoxes("chkAlumHalf").Value = 1 Then
Call ALUMHALF_PrepareForPrint
Call ALUMHALF_Print
End If
'Galvalume HALF Checkbox values are 0 (false), 1 (true), 2 (changed or grey)
If ActiveSheet.CheckBoxes("chkGalvHalf").Value = 1 Then
Call GALVHALF_PrepareForPrint
Call GALVHALF_Print
End If
'COPPER HALF Checkbox values are 0 (false), 1 (true), 2 (changed or grey)
If ActiveSheet.CheckBoxes("chkCopperHalf").Value = 1 Then
Call COPPERHALF_PrepareForPrint
Call COPPERHALF_Print
End If
'CC Checkbox values are 0 (false), 1 (true), 2 (changed or grey)
If ActiveSheet.CheckBoxes("chkAdmin").Value = 1 Then
Call Admin_Print
End If
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi,
welcome to the forum

Two suggestions

1 - if any of the codes you call changes the sheet the checkboxes reside on then replace ActiveSheet (shown in RED) with the actual sheet name

Rich (BB code):
If ActiveSheet.CheckBoxes("chk3installcopies").Value = 1 Then

2 - ensure the spelling for each of your checkbox names are all correct.

Dave
 
Last edited:
Upvote 0
I think suggestion number 1 is the solution! Thank you so much.

Most welcome glad suggestion resolved.

Untested but an alternative approach you can try

Code:
Sub PrintSelectedSheets()
    Dim Checkbox As Object
    Dim i As Integer
    For Each Checkbox In Worksheets("Sheet1").CheckBoxes
        i = i + 1
        If Checkbox.Value = 1 Then PrintSheets i
    Next Checkbox
End Sub




Sub PrintSheets(ByVal PrintSelection As Integer)
    Select Case PrintSelection
    Case 1
        Call InstallerCopyWPrint
    Case 2
        Call MISC_PrepareForPrint
        Call MISC_Print
    Case 3
        Call JobNotes_Print
    Case 4
        Call ALUM_PrepareForPrint
        Call ALUM_Print
    Case 5
        Call GALV_PrepareForPrint
        Call GALV_Print
    Case 6
        Call COPPER_PrepareForPrint
        Call COPPER_Print
    Case 7
        Call ALUMHALF_PrepareForPrint
        Call ALUMHALF_Print
    Case 8
        Call GALVHALF_PrepareForPrint
        Call GALVHALF_Print
    Case 9
        Call COPPERHALF_PrepareForPrint
        Call COPPERHALF_Print
    Case 10
        Call Admin_Print
    End Select
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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