Unprotecting/protecting a sheet using VBA is much slower in Excel 365 compared to Excel 2007. Does anyone have the slightest idea as to why this is the case? And is there anything that can be done to resolve this without just omitting the protect-functions?
To make sure the issue is caused solely by the unprotect/protect statements, I tested with a blank workbook containing a single module with the following code:
Dim secondsElapsed As Double
startTime = Timer
Sheets("test").Unprotect ("****")
ThisWorkbook.Sheets("Timers").Cells(1, 1) = Round(Timer - startTime, 2)
startTime = Timer
Sheets("test").Protect Password:="****", DrawingObjects:=False, Contents:=True, Scenarios:=True, AllowSorting:=True, AllowFiltering:=True
ThisWorkbook.Sheets("Timers").Cells(2, 1) = Round(Timer - startTime, 2)
`
This yields the following averages:
- Excel 2007
- unprotect: 0.02 seconds
- protect: 0.01 seconds
- Excel 365
- unprotect: 0.52 seconds
- protect: 0.47 seconds