Hello Can anyone help me:
I am trying to crack away to protect my workbook, by forcing users the enable macros on launching.
What I am trying to do is if Workbook_BeforeSave runs a routine called DoIt. This calls HideAll, saves, then calls ShowAll al whilst not updating. (ie so the user is non the wiser and the computer does not asked to save again if no changes are made).
The reason I am trying this is so that if the user closes the document, it will not ask them again to save. Instead it has preserved the state in the HideAll place (ie all important worksheets are VeryHidden.
It is only by enabling Macros on open can the ShowAll make them visible again.
Below is the code I am using and it works, except it seems the Application.EnableEvents = False in the DoIt macro does not seem to be doing what it should.
can anyone help show me what I am dong wrong?
very dearly love to get an answer as it is driving me up the wall!
Module 1:
This Workbook:
thanks so much
johnny
I am trying to crack away to protect my workbook, by forcing users the enable macros on launching.
What I am trying to do is if Workbook_BeforeSave runs a routine called DoIt. This calls HideAll, saves, then calls ShowAll al whilst not updating. (ie so the user is non the wiser and the computer does not asked to save again if no changes are made).
The reason I am trying this is so that if the user closes the document, it will not ask them again to save. Instead it has preserved the state in the HideAll place (ie all important worksheets are VeryHidden.
It is only by enabling Macros on open can the ShowAll make them visible again.
Below is the code I am using and it works, except it seems the Application.EnableEvents = False in the DoIt macro does not seem to be doing what it should.
can anyone help show me what I am dong wrong?
very dearly love to get an answer as it is driving me up the wall!
Module 1:
Code:
Public bIsClosing As Boolean
Dim wsSheet As Worksheet
Sub HideAll()
Application.ScreenUpdating = False
For Each wsSheet In ThisWorkbook.Worksheets
If wsSheet.Name = "Warning" Or wsSheet.Name = "Authorise" Then
wsSheet.Visible = xlSheetVisible
Else
wsSheet.Visible = xlSheetVeryHidden
End If
Next wsSheet
Application.ScreenUpdating = True
ThisWorkbook.Sheets("Warning").Activate
End Sub
Sub ShowAll()
Application.ScreenUpdating = False
bIsClosing = False
Dim wsDropList As Worksheet
For Each wsSheet In ThisWorkbook.Worksheets
If wsSheet.Name <> "Warning" Then
wsSheet.Visible = xlSheetVisible
End If
Next wsSheet
Sheet1.Visible = xlSheetVeryHidden
Sheet5.Visible = xlSheetVeryHidden
ThisWorkbook.Sheets("Budget").Activate
End Sub
This Workbook:
Code:
Private Sub Workbook_Open()
Call ShowAll
ThisWorkbook.Sheets("Budget").Activate
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Call DoIt
Cancel = True
End Sub
Sub DoIt()
Application.EnableEvents = False
Call HideAll
ThisWorkbook.Save
Call ShowAll
Application.EnableEvents = True
End Sub
thanks so much
johnny