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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
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
 
Upvote 0

Forum statistics

Threads
1,215,040
Messages
6,122,806
Members
449,095
Latest member
m_smith_solihull

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