I have some vba code to protect and unprotect the sheets in my workbook. This code runs fine (IE as expected) on Excel for Windows 2007, 2010 and Excel for MAC 2011 but in Excel for Windows 2019 it switches sheets when run.
The Workbook has 6 sheets and the code below runs from a button on Sheet6;
</code>
What happens normally (on 2007,2010 & 2011 for MAC) is that after running the code, the button text changes and we are still on the sheet with the button (sheet6); in 2019, the code runs but we are then on Sheet5.
Call S_Off and Call S_On call code like this;
<code>
</code>
But commenting those calls out makes NO difference to the result.
The button that calls the ‘Unprotect code looks like this;
<code>
</code>
So it calls Protection_Off if Sheet4 is currently protected, or Protection_On if Sheet4 is not currently protected allowing the protection status to be toggled on and off based on the status of Sheet4; I only add this explanation for completeness, I don’t think it has anything to do with the problem.
When the call to Protection_On is made, the problem of switching sheets does NOT happen.
I have tested commenting out all other code except turning the Protection_Off and the problem persists.
Any ideas on why the difference most welcome.
Thanks
The Workbook has 6 sheets and the code below runs from a button on Sheet6;
Code:
<code> Call S_Off ' Turn Off Calc & Screen Updates
Sheet1.Unprotect Password:="" '
Sheet2.Unprotect Password:="" '
Sheet3.Unprotect Password:="" '
Sheet4.Unprotect Password:="" '
Sheet5.Unprotect Password:="" '
Sheet6.Unprotect Password:="" '
' Reflect Change on Control Button
Sheet6.Buttons("Button_Protect").Text = "Protect OFF"
Sheet6.Buttons("Button_Protect").Font.ColorIndex = 3
Call S_On
What happens normally (on 2007,2010 & 2011 for MAC) is that after running the code, the button text changes and we are still on the sheet with the button (sheet6); in 2019, the code runs but we are then on Sheet5.
Call S_Off and Call S_On call code like this;
Code:
<code>Sub S_Off() ' Turn Updating & Calculation OFF
Application.ScreenUpdating = False '
Application.Calculation = xlCalculationManual '
End Sub '
Sub S_On() ' Turn Updating & Calculation ON
Application.Calculation = xlCalculationAutomatic '
Application.ScreenUpdating = True '
End Sub</code>
</code>
But commenting those calls out makes NO difference to the result.
The button that calls the ‘Unprotect code looks like this;
<code>
Code:
Sub Button_Toggle_Protection() </code>
<code> If Sheet4.ProtectContents = True Then
Call Protect_Off(False)
Else
Call Protect_On(False)
If Application.EnableEvents = False Then
Call Button_Toggle_Events
End If
End If
End Sub
So it calls Protection_Off if Sheet4 is currently protected, or Protection_On if Sheet4 is not currently protected allowing the protection status to be toggled on and off based on the status of Sheet4; I only add this explanation for completeness, I don’t think it has anything to do with the problem.
When the call to Protection_On is made, the problem of switching sheets does NOT happen.
I have tested commenting out all other code except turning the Protection_Off and the problem persists.
Any ideas on why the difference most welcome.
Thanks