Protect command bars against changes

Article contributed by Bill Coan

To protect the command bars:

Dim oCommandBar As CommandBar
'NOTE: enable exactly one CustomizationContext statement:
'CustomizationContext = NormalTemplate
'CustomizationContext = ActiveDocument.AttachedTemplate
For Each oCommandBar In CommandBars
    If oCommandBar.Visible = True Then
        oCommandBar.Protection = msoBarNoChangeDock + _
          msoBarNoChangeVisible + msoBarNoCustomize + _
          msoBarNoMove + msoBarNoResize
    End If
Next oCommandBar

To remove protection again:

Dim oCommandBar As CommandBar
On Error Resume Next

'NOTE: enable exactly one CustomizationContext statement:
'CustomizationContext = NormalTemplate
'CustomizationContext = ActiveDocument.AttachedTemplate
For Each oCommandBar In CommandBars
    oCommandBar.Protection = msoBarNoProtection
Next oCommandBar


Click to view Terms of Use page

Click to view Disclaimer page