Hi,
The Workbook_Open event is a procedure of the Workbook Object and as such, the Workbook_Open procedure MUST reside in the private module of the Workbook Object (ThisWorkbook).
To achieve this while in VBE double click the module called ThisWorkbook. Here you can add the code you wish to run on open, for example
Code:
Private Sub Workbook_Open()
Worksheets("sheetname").Visible = False
MsgBox ("sheetname is hidden")
End Sub
To get your on close event to run is a slightly more complex matter. Excel's before close event runs before a workbook is closed. However if you attempt to close a workbook that has not been saved your prompted with a message encouraging you to save. By the time this message appears the 'before close' event has already run. It is therefore possible to run the code for a workbook close but to keep the workbook open (by cancelling the prompt to save changes). One solution to this problem is...
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Not Me.Saved Then
Msg = "Do you want to save the changes you made to "
Msg = Msg & Me.Name & "?"
Ans = MsgBox(Msg, vbQuestion + vbYesNoCancel)
Select Case Ans
Case vbYes
Me.Save
Case vbNo
Me.Saved = True
Case vbCancel
Cancel = True
Exit Sub
End Select
End If
Worksheets("sheetname").Visible = True
MsgBox ("sheetname is visible")
End Sub
Hope this helps,
Dave