Workbook open event

zenahs

New Member
Joined
Nov 15, 2005
Messages
1
I have a workbook that requires a macro to perform the following tasks upon opening:

I need a pop-up to appear asking the user if he/she has read the appropriate security guidelines before using the workbook. If they click "yes", the workbook will open and all sheets will be unhidden (I need to have them hidden prior to opening just in case a user chooses to disable macros). If they choose "no", the workbook will close.
Any ideas??
Thanks in advance.
P.S. I'm a newbie to VBA so I apologize if this seems like a simple question
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Nimrod

MrExcel MVP
Joined
Apr 29, 2002
Messages
6,259
ASSUMPTON:
- The workbook has a sheet that is named "Sheet1"


Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim WS As Worksheet

    Sheets("Sheet1").Visible = xlSheetVisible
    
    For Each WS In ThisWorkbook.Worksheets
        If Not WS.Name = "Sheet1" Then
            WS.Visible = xlSheetVeryHidden
        End If
    Next WS

End Sub

Private Sub Workbook_Open()
Dim WS As Worksheet

    msg = "Have you read the secuity stuff ?"
    Title = "Read Security"
    Style = vbQuestion + vbYesNo
    
    If MsgBox(msg, Style, Title) = vbYes Then
    
        For Each WS In ThisWorkbook.Worksheets
            If Not WS.Name = "Sheet1" Then
                WS.Visible = xlSheetVisible
            End If
        Next WS
        
        Sheets("Sheet1").Visible = xlSheetVeryHidden
        
    Else
        ThisWorkbook.Close
    End If

End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,133
Messages
5,835,594
Members
430,369
Latest member
pingel

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
Top