Force Macro Enable/Disable

Maurush

New Member
Joined
Feb 9, 2011
Messages
42
Hello guys,

I have a problem concerning macro's ... I made an excel workbook that will
show a sheet if macro's are disabled. Only that sheet will appear, in which it says
that people need to enable the macro's, close the file and then reopen.

When macro's are enabled people will not see that sheet again, and can start
answering questions and go through the rest of my sheets.

I found some files doing that under the name 'Splash' I don't know if anybody is familiar
with that term.

Anyway the problem is the following, I have multiple sheets that I want to show,
but I always want to start with the sheet called "Start Enquete" ... but the problem I
have is that other pages will show, after I have saved the file or quit the program.

The codes that I have are the following:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)

    With Application
        .EnableCancelKey = xlDisabled
        .ScreenUpdating = False

        Call HideSheets

        .ScreenUpdating = True
        .EnableCancelKey = xlInterrupt
    End With

    ThisWorkbook.Save
    ThisWorkbook.Saved = True

End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

    With Application
        .EnableCancelKey = xlDisabled
        .ScreenUpdating = False

        Call HideSheets

        .ScreenUpdating = True
        .EnableCancelKey = xlInterrupt
    End With

    ThisWorkbook.Save
    ThisWorkbook.Saved = True

End Sub

Private Sub Workbook_Open()
    
ActiveSheet.Unprotect ("")
    
    'Unhide all worksheets
    
            With Application
                .EnableCancelKey = xlDisabled
                .ScreenUpdating = False
        
                Call UnhideSheets
        
                .ScreenUpdating = True
                .EnableCancelKey = xlInterrupt
            End With
         
ActiveSheet.Protect ("")
        
End Sub

Private Sub HideSheets()

Dim Sheet As Object

    With Sheets("Macros")
        .Visible = xlSheetVisible
            For Each Sheet In Sheets
                If Not Sheet.Name = "Macros" Then
                    Sheet.Visible = xlSheetVeryHidden
                End If
            Next
        Set Sheet = Nothing
    End With

End Sub

Private Sub UnhideSheets()

    Sheets("Start Enquéte").Visible = xlSheetVisible
    Sheets("Macros").Visible = xlSheetVeryHidden
    Sheets("Clustermanagers blad 1").Visible = xlSheetVisible
    Sheets("Clustermanagers blad 2").Visible = xlSheetVisible
    Sheets("Clustermanagers blad 3").Visible = xlSheetVisible
    Sheets("Clustermanagers blad 4").Visible = xlSheetVisible
    Sheets("End").Visible = xlSheetVisible
       
End Sub
What do I need to change at the code so that always when open the file,
when macro's are enabled, the file starts with Sheets("Start Enquéte")???

Thanks for the help!!
 
If macros are disabled your workbook_open won't do anything. So no, wrong.

I finally found the solution, and I didn't need to put the part .select at the end of the unhidesheet.

I have used the following codes for the hide/unhiding of the sheets:

Code:
Private Sub HideSheets()

Dim Sheet As Object

    With sheets("EnableMacro")
        .Visible = xlSheetVisible
            For Each Sheet In sheets
                If Not Sheet.Name = "EnableMacro" Then
                    Sheet.Visible = xlSheetVeryHidden
                End If
            Next
        Set Sheet = Nothing
    End With

End Sub

Private Sub UnhideSheets()

    sheets("Start Enquéte").Visible = xlSheetVisible
    sheets("EnableMacro").Visible = xlSheetVeryHidden

End Sub
With the subs BeforeClose and BeforeSave I have used the following (both the same code):

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

        With Application
        .EnableCancelKey = xlDisabled
        .ScreenUpdating = False

        Call HideSheets

        .ScreenUpdating = True
        .EnableCancelKey = xlInterrupt
    
    End With

    ThisWorkbook.Save
    ThisWorkbook.Saved = True

End Sub
But I also put this code in the Commandbutton:

Code:
Private Sub CommandButton11_Click()

        If ComboBox1.Value > 1 And ComboBox2.Value = "Nee" Then
                      
             If MsgBox("Weet u zeker dat u het document wilt opslaan en afsluiten?", vbYesNo + vbQuestion, "Bestand opslaan en afsluiten") = vbYes Then
                                                                              
                        With Application
                        .EnableCancelKey = xlDisabled
                        .ScreenUpdating = False
                
                        Call HideSheets
                
                        .ScreenUpdating = True
                        .EnableCancelKey = xlInterrupt
                    
                    End With
                
                    ThisWorkbook.Save
                    ThisWorkbook.Saved = True
                    ActiveWorkbook.Close

             End If
I found out that when I closed the file everything was working correctly, but when I saved it with
the commandbutton, after reopening the workbook the worksheet that appeared was the last one
before closing. This when I did not put your part in Glenn, sheet("..").select. --> this helped me open the first sheet if macros were enabled.
But if the macros were disabled, I couldn't get the right worksheet appear.

The last thing that is important is the sub workbook_open() here you need to call unhide sheets:

Code:
            With Application
                .EnableCancelKey = xlDisabled
                .ScreenUpdating = False
        
                Call UnhideSheets
        
                .ScreenUpdating = True
                .EnableCancelKey = xlInterrupt
            End With
With those codes it is possible to always show a screen when macros are disabled with
information about switching macros on. After close as well as save.

I hope it will be handy for someone someday! Anyway thanks Glenn for your help.

Maurush.
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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