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
 

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

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
 

Watch MrExcel Video

Forum statistics

Threads
1,118,055
Messages
5,569,948
Members
412,299
Latest member
agentless
Top