Z
zwestbrook
I am trying to do the disabled macros workaround but can't get it to
work...I cannot figure out what I have done wrong in my code...any
help is appreciated.
[ Workbook Open ]
Private Sub Workbook_Open()
' hide the toolbars
' turn them back on from the 'admin' tab and when closing the workbook
'Dim a As Integer
'For a = 1 To Application.CommandBars.Count
' Application.CommandBars(a).Enabled = False
'Next
' turn back on the standard toolbar to allow saving
Application.CommandBars("Standard").Enabled = True
' show and take the user to the welcome sheet
Worksheets("Welcome").Visible = True
Worksheets("Welcome").Activate
' hide the macro notification sheet
Worksheets("Enable_Macros").Visible = False
'**********************************************************************************
' perform checks on user id and show corresponding sheets
'**********************************************************************************
If Environ("username") = "a499025" Then
Worksheets("Zac").Visible = True
Worksheets("Admin").Visible = True
Else
<snip>
' user is not found, show error sheet and hide the welcome sheet
Worksheets("Error!").Visible = True
Worksheets("Error!").Activate
Worksheets("Welcome").Visible = xlVeryHidden
Dim ErrorMsg
ErrorMsg = MsgBox("I'm Sorry, You Do Not Have Access!" _
, vbOKOnly + vbCritical, "E R R O R ! ! !")
End If
'**********************************************************************************
'end user id checks
'**********************************************************************************
' hide the task pane
Application.CommandBars("Task Pane").Visible = False
' turn off Excel alert messages
Application.DisplayAlerts = False
End Sub
[ Workbook OnBeforeClose ]
Private Sub Workbook_BeforeClose(Cancel As Boolean)
' MsgBox ("save check") 'turn on to check close looping
' check to see if user has saved the file
' and warn them before closing if the document is unsaved
Dim exitMsg
If Not ActiveWorkbook.Saved Then 'if the document has NOT been saved
exitMsg = MsgBox("This workbook contains unsaved changes." _
& Chr(13) & "Do you want to continue without saving?"
_
, vbYesNo + vbCritical + vbDefaultButton2, "W A R N I
N G ! ! !")
If exitMsg = vbNo Then 'user says they don't want to continue
Cancel = True 'cancel closing the document
Exit Sub 'stop running the code
End If
End If
' bring the toolbars back
Dim a As Integer
For a = 1 To Application.CommandBars.Count
Application.CommandBars(a).Enabled = True
Next
' turn on the "Macros" sheet for next user
Worksheets("Enable_Macros").Visible = True
Worksheets("Enable_Macros").Activate
' hide all sheets to prevent next user from seeing them
For Each ws In Worksheets
If ws.Name <> "Enable_Macros" Then ws.Visible = xlVeryHidden
Next
' set the save flag to avoid prompt
ActiveWorkbook.Saved = True
ActiveWorkbook.Close
' ensure Excel alerts are turned on
Application.DisplayAlerts = True
End Sub
work...I cannot figure out what I have done wrong in my code...any
help is appreciated.
[ Workbook Open ]
Private Sub Workbook_Open()
' hide the toolbars
' turn them back on from the 'admin' tab and when closing the workbook
'Dim a As Integer
'For a = 1 To Application.CommandBars.Count
' Application.CommandBars(a).Enabled = False
'Next
' turn back on the standard toolbar to allow saving
Application.CommandBars("Standard").Enabled = True
' show and take the user to the welcome sheet
Worksheets("Welcome").Visible = True
Worksheets("Welcome").Activate
' hide the macro notification sheet
Worksheets("Enable_Macros").Visible = False
'**********************************************************************************
' perform checks on user id and show corresponding sheets
'**********************************************************************************
If Environ("username") = "a499025" Then
Worksheets("Zac").Visible = True
Worksheets("Admin").Visible = True
Else
<snip>
' user is not found, show error sheet and hide the welcome sheet
Worksheets("Error!").Visible = True
Worksheets("Error!").Activate
Worksheets("Welcome").Visible = xlVeryHidden
Dim ErrorMsg
ErrorMsg = MsgBox("I'm Sorry, You Do Not Have Access!" _
, vbOKOnly + vbCritical, "E R R O R ! ! !")
End If
'**********************************************************************************
'end user id checks
'**********************************************************************************
' hide the task pane
Application.CommandBars("Task Pane").Visible = False
' turn off Excel alert messages
Application.DisplayAlerts = False
End Sub
[ Workbook OnBeforeClose ]
Private Sub Workbook_BeforeClose(Cancel As Boolean)
' MsgBox ("save check") 'turn on to check close looping
' check to see if user has saved the file
' and warn them before closing if the document is unsaved
Dim exitMsg
If Not ActiveWorkbook.Saved Then 'if the document has NOT been saved
exitMsg = MsgBox("This workbook contains unsaved changes." _
& Chr(13) & "Do you want to continue without saving?"
_
, vbYesNo + vbCritical + vbDefaultButton2, "W A R N I
N G ! ! !")
If exitMsg = vbNo Then 'user says they don't want to continue
Cancel = True 'cancel closing the document
Exit Sub 'stop running the code
End If
End If
' bring the toolbars back
Dim a As Integer
For a = 1 To Application.CommandBars.Count
Application.CommandBars(a).Enabled = True
Next
' turn on the "Macros" sheet for next user
Worksheets("Enable_Macros").Visible = True
Worksheets("Enable_Macros").Activate
' hide all sheets to prevent next user from seeing them
For Each ws In Worksheets
If ws.Name <> "Enable_Macros" Then ws.Visible = xlVeryHidden
Next
' set the save flag to avoid prompt
ActiveWorkbook.Saved = True
ActiveWorkbook.Close
' ensure Excel alerts are turned on
Application.DisplayAlerts = True
End Sub