Workbook_BeforeClose

S

Sandy

I have the following but it does not run when closing workbook - Any ideas?
(I am assuming the message box should pop up?)

Private Sub Workbook_BeforeClose(Cancel As Boolean)

MsgBox "Hello"

Application.ScreenUpdating = False
Application.EnableEvents = False

Sheets("Current Round").Unprotect Password:="xxxxx"
Sheets("Current Round Detailed").Unprotect Password:="xxxxx"
Sheets("Current Round Graph").Unprotect Password:="xxxxx"
Sheets("Home Graphs").Unprotect Password:="xxxxx"
Sheets("Home Detailed Graphs").Unprotect Password:="xxxxx"
Sheets("All Rounds").Unprotect Password:="xxxxx"
Sheets("View Rounds").Unprotect Password:="xxxxx"


Sheets("Current Round").Visible = True
Sheets("Current Round Detailed").Visible = True
Sheets("Current Round Graph").Visible = True
Sheets("Home Graphs").Visible = True
Sheets("Home Detailed Graphs").Visible = True
Sheets("All Rounds").Visible = True
Sheets("View Rounds").Visible = True

Sheets("RecordOfRounds").Visible = xlSheetVeryHidden
Sheets("RecordOfRoundsDetailed").Visible = xlSheetVeryHidden
Sheets("HomeCourse").Visible = xlSheetVeryHidden
Sheets("HomeDetailed").Visible = xlSheetVeryHidden
Sheets("LogGraph1").Visible = xlSheetVeryHidden
Sheets("LogGraph2").Visible = xlSheetVeryHidden
Sheets("LogGraph3").Visible = xlSheetVeryHidden
Sheets("LogGraph4").Visible = xlSheetVeryHidden
Sheets("LogGraph5").Visible = xlSheetVeryHidden
Sheets("LogGraph6").Visible = xlSheetVeryHidden
Sheets("LogGraph7").Visible = xlSheetVeryHidden

Sheets("Current Round").Select

Dim Wksht As Worksheet

With Application
.DisplayFormulaBar = True
.CommandBars("Worksheet Menu Bar").Enabled = True
.CommandBars("Standard").Visible = True
.CommandBars("Formatting").Visible = True
.CommandBars("Drawing").Visible = True
End With

For Each Wksht In Worksheets(Array("Current Round", "Current Round
Detailed", _
"Current Round Graph", "Home Detailed Graphs", "Home Graphs", "All
Rounds", "View Rounds", "LogGraph3"))

Wksht.Activate
ActiveWindow.DisplayHeadings = True

Next

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub

Thanks
Sandy
 
M

Mike H

Hi,

If this isn't running and I agree it should pop up the message box then
events may be disabled.
rRght click any sheet tab, view code and paste this in and run it

Sub enableem()
Application.EnableEvents = True
End Sub

then try you before_close routine again. When disbling events using code you
should do so at the last point in the code possible. If you disable early and
the code crashes you can be left with events disabled.

Mike
 
S

Sandy

Hi Mike

Yes my stupidity, events had been turned off in the Workbook_Open.

Thanks
Sandy
 
J

Jim May

"had been turned off in the Workbook_Open"

Sandy, I believe it is better to say that when events are turned off ALL
EVENTS are turned off, not just the Workbook_Open. << FWIW

Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top