UserInterfaceOnly not kicking in when accessed through ribbon button

Lance-R

New Member
Joined
Apr 28, 2008
Messages
13
I have a large workbook, wherein I use UserInterfaceOnly on the sheets implemented through the Workbook_Activate event. Up until now it's always worked just fine, but now it doesn't work in a specific circumstance.

When I open the file directly or with a shortcut or with the File->Open command, it works just fine.

When I open it with a custom ribbon button (which has always worked fine), the workbook opens and both the Open and Activate events run, but the protection isn't applied. So most of the sheets will have full protection, and if the Workbook was closed with protection removed on a a sheet (usually during troubleshooting) then it opens without protection.

The routines are pretty simple, but I'll copy them here so I don't get requests for them.

First, the ThisWorkbook module:

Code:
Option Explicit

Private Sub Workbook_Activate()

Application.ScreenUpdating = False

Dim wsheet As Worksheet
For Each wsheet In ThisWorkbook.Worksheets
    Call ProtectSheetInterface(wsheet)
Next wsheet

Application.ScreenUpdating = True

End Sub

Private Sub Workbook_Open()

Call WidenNameBoxDrop2

End Sub

Then the protection routine:

Code:
Public Sub ProtectSheetInterface(wsheet As Worksheet)

wsheet.Protect Password:="xxxxxx", UserInterfaceOnly:=True

End Sub

Then the CustomUI for the ribbon group (The workbook in question is the Operations one):

Code:
<customui xmlns="http://schemas.microsoft.com/office/2009/07/customui">

  <!-- Add Custom group to the Home tab in the ribbon -->
  <!-- This is for switching between workbooks in Dispatch Accounting, and for saving them -->

  <ribbon>
    <tabs> 

      <tab idmso="TabHome">
        <group id="GoToGroup" label="GoTo" insertaftermso="GroupEditingExcel">

          <button id="OperationsButton" label="Operations" onaction="GoToOperations">
          </button><button id="ForecastButton" label="Forecast" onaction="GoToForecast">
          </button><button id="LogsButton" label="Logs" onaction="GoToLogs">
          
      <separator id="MySeparator1">

          </separator></button><button id="CgasButton" label="Cgas" onaction="GoToCgas">
          </button><button id="SaveAllButton" label="Save All"  onaction="SaveAllWorkbooks">
          </button><button id="SaveCloseButton" label="Save Close"  onaction="SaveClose">

Here is the relevant callback and code it calls:
Code:
Public Sub SwapWorkbooks(fname As String, newpath As String)

'Windows(1).WindowState = xlMinimized

On Error GoTo OpenTheSheet
    Workbooks(fname).Activate
    ActiveSheet.EnableCalculation = False
    ActiveSheet.EnableCalculation = True
    Windows(1).Visible = True
    Windows(1).WindowState = xlMaximized
    
Exit Sub

OpenTheSheet:
    Workbooks.Open Filename:=newpath, UpdateLinks:=xlUpdateLinksAlways
    Workbooks(fname).Activate
    ActiveSheet.EnableCalculation = False
    ActiveSheet.EnableCalculation = True
    Windows(1).Visible = True
    Windows(1).WindowState = xlMaximized
    ActiveWindow.DisplayWorkbookTabs = True
    ActiveSheet.EnableSelection = xlNoRestrictions
  
End Sub

Public Sub GoToOperations(control As IRibbonControl)

Call SwapWorkbooks("Operations.xlsm", ThisWorkbook.Path + "\Operations.xlsm")

End Sub

Now, here's what I was doing that precipitated this all happening.

1) I inserted a new sheet, with some professional custom controls (not created by me), that originally had some excel charts in them, but they were deleted. I have since gone back in and deleted the shapes that were ghosted in.

2) While doing this I notice that my original custom menu from when this was an Excel 2003 sheet was still in there, so I deleted that module and sheet. There is no code connection between those and the ribbon.

Any ideas on why opening this workbook through the ribbon button won't implement protection?</button></group></tab></tabs></ribbon></customui>
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top