I have a worksheet with a userform with 24 checkboxes that I am attempting to use to open a workbook with 24 different worksheets. I want to use the checkboxes to select which sheets to print. The checkbox.captions correspond to the worksheet names and the checkbox.names correspond to the position of the worksheets I want to print. I have tried building a string to work from without success. My latest attempt was to build an array, but I haven't fared much better. I've worked on this till me head is spinning. Please help!
Code:
Sub SOTForm()
Dim MyArray() As Variant
Dim wb As Workbook
Dim i As Integer
Dim j As Integer
Dim s As Integer
Dim ctrl As Control
Set wb = Workbooks.Open("me.xlsx", ReadOnly:=True)
j = 0
For Each ctl In UserForm1.Controls
If TypeOf ctl Is MSForms.CheckBox Then
If UserForm1.Controls(ctl.Name).Value = True Then
j = j + 1
End If
End If
Next
For s = 0 To j
For i = 1 To 24
If ThisWorkbook.UserForm1.Controls("checkbox" & i).Value = True Then
MyArray(s) = i
End If
Next i
Next s
wb.Sheets(Array(mystring)).Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
End Sub