In order to understand how the whole code structure works, I recommend uncommenting all the Stops and going through the code in step mode.
All the changed code in the ThisWorkbook module. The rest remains unchanged.:
Option Explicit
Const WelcomePage$ = "Introduction"
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Answer As VbMsgBoxResult
'Stop
'custom save support when closing the workbook
If Me.Saved = False Then
Answer = MsgBox("Want to save your changes to '" & Me.Name & "'?" & Space(20), _
vbYesNoCancel + vbExclamation + vbDefaultButton1)
Select Case Answer
Case vbYes
Call SaveMe
Case vbNo
Me.Saved = True
Case vbCancel
Cancel = True
End Select
End If
End Sub
Private Sub Workbook_Open()
'Stop
Application.ScreenUpdating = False
Call ApplicationSettings(False)
Call EnableEdit(True)
Application.ScreenUpdating = True
ThisWorkbook.Saved = True
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim ws As Object
Dim wsActive As Object
Dim vFilename As Variant
'Stop
'Turn off screen flashing
Application.ScreenUpdating = False
'Record active sheet
Set wsActive = ActiveSheet
'Save workbook directly or prompt for saveas filename
If SaveAsUI Then
vFilename = Application.GetSaveAsFilename( _
fileFilter:="Excel Files (*.xls*), *.xls*")
If TypeName(vFilename) = "Boolean" Then
'Stop
Else
'Save the workbook using the supplied filename
Application.EnableEvents = False
Call EnableEdit(False)
ThisWorkbook.SaveAs vFilename
Application.RecentFiles.Add vFilename
Call EnableEdit(True)
wsActive.Select
Me.Saved = True
Application.EnableEvents = True
End If
Else
Call SaveMe
End If
'Stop
Cancel = True
End Sub
Private Sub SaveMe()
Dim Sh As Object
'Stop
Set Sh = ActiveSheet
Application.EnableEvents = False
Call EnableEdit(False)
Me.Save
Call EnableEdit(True)
Sh.Select
Me.Saved = True
Application.EnableEvents = True
End Sub
Sub EnableEdit(blnEnable As Boolean)
Dim ws As Object
Dim a
Dim i As Integer
'Stop
a = Array(WelcomePage)
With ThisWorkbook
On Error Resume Next
i = .Sheets(a).Count
On Error GoTo 0
If i <> UBound(a) + 1 Then Exit Sub
Application.ScreenUpdating = False
Call fileProtection(False)
For i = 0 To UBound(a)
.Sheets(a(i)).Visible = xlSheetVisible
Next
For Each ws In .Sheets
If IsError(Application.Match(ws.Name, a, 0)) Then
ws.Visible = IIf(blnEnable, xlSheetVisible, xlSheetVeryHidden)
End If
Next
For i = 0 To UBound(a)
.Sheets(a(i)).Visible = IIf(blnEnable, xlSheetVeryHidden, xlSheetVisible)
Next
Call fileProtection(True)
Application.ScreenUpdating = True
End With
End Sub
Artik
Bookmarks