Excel

Creating a temporary audit toolbar to trace dependents & precedents on a protected sheet

Ease of Use

Intermediate

Version tested with

2000, 2003 

Submitted by:

brettdj

Description:

A new temporary command bar containing the five key audit icons pops up 

Discussion:

A corporate master template is sent out for data entry but the sheets are protected so that the formulas and layout cannot be changed. When a worksheet is protected the audit toolbar no longer functions. This code provides a floating look alike toolbar that unprotects the active sheet, runs the audit and then protects the sheet again. The toolbar is deleted when the workbook that contains the code is closed 

Code:

instructions for use

			

**** ThisWorkbook Module ***** Private Sub Workbook_BeforeClose(Cancel As Boolean) KillBar End Sub Private Sub Workbook_Open() MakeBar End Sub **** New Code Module ***** Option Explicit Public Const TempAuditBar = "Temp Audit Bar" Public Const MyPassword = "integrity" Sub MakeBar() Dim NewMenu As CommandBar Dim Ctrl As CommandBarControl Dim i As Integer KillBar Set NewMenu = Application.CommandBars.Add(TempAuditBar, msoBarFloating, False, True) With NewMenu .Controls.Add Type:=msoControlButton, ID:=486 .Controls.Add Type:=msoControlButton, ID:=452 .Controls.Add Type:=msoControlButton, ID:=451 .Controls.Add Type:=msoControlButton, ID:=450 .Controls.Add Type:=msoControlButton, ID:=453 End With For Each Ctrl In NewMenu.Controls Ctrl.OnAction = ThisWorkbook.Name & "!TP" Next With NewMenu .Visible = True .Protection = msoBarNoChangeVisible End With End Sub Sub TP() ThisWorkbook.ActiveSheet.Unprotect MyPassword Select Case Application.CommandBars.ActionControl.ID Case 486 Selection.ShowPrecedents Case 452 Selection.ShowPrecedents Remove:=True Case 451 Selection.ShowDependents Case 450 Selection.ShowDependents Remove:=True Case 453 ActiveSheet.ClearArrows End Select ThisWorkbook.ActiveSheet.Protect MyPassword End Sub Sub KillBar() On Error Resume Next Application.CommandBars(TempAuditBar).Delete On Error GoTo 0 End Sub

How to use:

  1. Copy the code above.
  2. Open your workbook.
  3. Hit Alt+F11 to open the Visual Basic Editor (VBE).
  4. Paste the first section of code into the ThisWorkbook module
  5. From the menu, choose Insert-Module.
  6. Paste the second section of code into the code window at right.
  7. Close the VBE, and save the file if desired.
 

Test the code:

  1. The command bar will appear when the file is opened.
  2. Please note, when any icon of this temporary toolbar is pressed the code will attempt to unprotect, then function, and then reprotect the sheet with the password stored in MyPassword , ie "integrity" in the case above.
 

Sample File:

No Attachment 

Approved by mvidas


This entry has been viewed 244 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express