currently i'm using the following code to produce a dialog box that lists all sheets within a workbook.
It's set up to start listing any sheet after the first 29 into a second column, but I now have so many sheets that I'll be needing a 3rd, 4th, and 5th columns, and possibly even more.
My alignment and spacing of columns needs adjusting but I'm sure i can tweak those myself, however, I don't know what to tweak to make multiple columns of 29.
Any ideas ?
Kind regards,
Chris
Code:
Option Explicit
Sub SelectSheets()
Dim i As Integer
Dim TopPos As Integer
Dim SheetCount As Integer
Dim PrintDlg As DialogSheet
Dim CurrentSheet As Worksheet
Dim cb As CheckBox
Application.ScreenUpdating = False
' Check for protected workbook
If ActiveWorkbook.ProtectStructure Then
MsgBox "Workbook is protected.", vbCritical
Exit Sub
End If
' Add a temporary dialog sheet
Set CurrentSheet = ActiveSheet
Set PrintDlg = ActiveWorkbook.DialogSheets.Add
SheetCount = 0
' Add the checkboxes
Dim Hor As Integer 'this will be for the horizontal position of the items
Hor = 78
Dim wd As Integer 'this will be for the overall width of the dialog box
wd = 230
For i = 1 To ActiveWorkbook.Worksheets.Count
Set CurrentSheet = ActiveWorkbook.Worksheets(i)
' Skip empty sheets and hidden sheets
If Application.CountA(CurrentSheet.Cells) <> 0 And _
CurrentSheet.Visible Then
SheetCount = SheetCount + 1
If SheetCount = 29 Then
Hor = 160
wd = 320
TopPos = 30
End If
PrintDlg.CheckBoxes.Add Hor, TopPos, 150, 16.5
PrintDlg.CheckBoxes(SheetCount).Text = _
CurrentSheet.Name
TopPos = TopPos + 13
End If
Next i
' Move the OK and Cancel buttons
PrintDlg.Buttons.Left = 240
' Set dialog height, width, and caption
With PrintDlg.DialogFrame
.Height = Application.Max _
(68, PrintDlg.DialogFrame.Top + TopPos - 34)
.Width = wd
.Caption = "Select sheets to print"
End With
' Change tab order of OK and Cancel buttons
' so the 1st option button will have the focus
PrintDlg.Buttons("Button 2").BringToFront
PrintDlg.Buttons("Button 3").BringToFront
' Display the dialog box
CurrentSheet.Activate
Application.ScreenUpdating = True
If SheetCount <> 0 Then
If PrintDlg.Show Then
For Each cb In PrintDlg.CheckBoxes
If cb.Value = xlOn Then
Worksheets(cb.Caption).Activate
ActiveSheet.PrintOut
' ActiveSheet.PrintPreview 'for debugging
End If
Next cb
End If
Else
MsgBox "All worksheets are empty."
End If
' Delete temporary dialog sheet (without a warning)
Application.DisplayAlerts = False
PrintDlg.Delete
' Reactivate original sheet
CurrentSheet.Activate
End Sub
It's set up to start listing any sheet after the first 29 into a second column, but I now have so many sheets that I'll be needing a 3rd, 4th, and 5th columns, and possibly even more.
My alignment and spacing of columns needs adjusting but I'm sure i can tweak those myself, however, I don't know what to tweak to make multiple columns of 29.
Any ideas ?
Kind regards,
Chris