Ungroup sheets

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Ungroup sheets

Post by ABabeNChrist »

I’m using checkboxes to make selection of which sheets to print, everything prints well but when I return back to workbook all worksheets are still selected and will not allow any code to run. What extra piece of code can I add to ungroup sheets?

Code: Select all

    Dim blnSelected As Boolean
    ActiveWorkbook.Protect PassWord:="", Structure:=False, Windows:=False

    Application.ScreenUpdating = False

    If CheckBox1.Value And Sheets("Cover Page").Visible = xlSheetVisible Then
        Sheets("Cover Page").Select Replace:=True
        blnSelected = True
    End If
    If CheckBox2.Value And Sheets("Client Information").Visible = xlSheetVisible Then
        Sheets("Client Information").Select Replace:=False
        blnSelected = True
    End If
    If CheckBox3.Value And Sheets("Utilities").Visible = xlSheetVisible Then
        Sheets("Utilities").Select Replace:=False
        blnSelected = True
    End If

    If blnSelected = True Then

        ActiveWindow.SelectedSheets.Application.Dialogs(xlDialogPrint).Show
        Unload Me
        ActiveWorkbook.Protect PassWord:="", Structure:=True, Windows:=True

    Else
        MsgBox "No check boxes were selected"

    End If
    Application.ScreenUpdating = True

User avatar
HansV
Administrator
Posts: 78619
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Ungroup sheets

Post by HansV »

Add a single line

Code: Select all

    ActiveSheet.Select
at the end.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Ungroup sheets

Post by ABabeNChrist »

Daaaaaaaaaaaa :stupidme:
Thank you Hans
I thought of that but wasn’t sure. I knew a single sheet needed to be selected to ungroup a selection of sheets and since I couldn’t select single sheet by name like so.
Sheets("Cover Page").Select.
Because sheet maybe hidden.