Hi dbischa,
Thanks! I think that will work, and I have had a go at trying to do it but my knowledge of VBA isn't that good. The before close event code that I have uses a command button that is killed if the close event doesn't fire. Is this what you mean by a flag? Either way I'm not sure exactly how to do what you have said (although I know what it will do).
Would you mind telling me how to set the flag, kill the save and then mark the workbook as saved? The bits in between I can do myself (I think).
I am overly tired and quite often thick-headed, so didn't quite follow killing a button etc. It appears by your last however, that you have done well in solving. What I meant by my last, in an admittedly rudimentary fashion would be something like:
Blank/New wb with 3 sheets, using default codenames.
Rich (BB code):
Option Explicit
Dim UserName As String
Dim Users() As Variant
Dim bInProcess As Boolean
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Not bInProcess Then
bInProcess = True
Sheet1.Visible = xlSheetVisible
Sheet2.Visible = xlSheetVeryHidden
Sheet3.Visible = xlSheetVeryHidden
Me.Save
Cancel = True
If Not IsError(Application.Match(Environ("UserName"), Users, 0)) Then
Sheet2.Visible = xlSheetVisible
Sheet3.Visible = xlSheetVisible
Sheet1.Visible = xlSheetHidden
Me.Saved = True
End If
bInProcess = False
End If
End Sub
Private Sub Workbook_Open()
Users() = Array("JON", "MARK", "ALICIA")
UserName = Environ("UserName")
If Not IsError(Application.Match(UserName, Users, 0)) Then
Sheet2.Visible = xlSheetVisible
Sheet3.Visible = xlSheetVisible
Sheet1.Visible = xlSheetHidden
Me.Saved = True
End If
End Sub
In gist, upon Open, see if we like the user. Yes? Show whatever sheets and (optionally) hide our "bug-off" sheet to non-authorized personnel.
If the user has macros disabled, no harm, as the other sheets are not exposed.
User OK + macros enabled: Ea time a save is called, we first hide stuff, then save, then unhide stuff and mark wb saved (just to eliminate pesky question from Excel if user then closes w/o further changes).
Thus, the wb is never actually in a saved status with our fanny hanging out (sheets visible).
As mentioned, I didn't
exactly follow all the solution, but looks nice
As a small comment, when I want a custom commandbar available to the wb, I use the Activate and Deactivate events. Activate runs after Open anyways (and Deactivate is fired before BeforeClose), so the CBAr is always restricted to teh WB.
hope that helps,
Mark