Workbook.Protect error with protection switching

When I call Thisworkbook.Protect in VBA, the workbook protection actually switches from the current protection status of the workbook, not just protecting the workbook.

Thisworkbook.Unprotect does not do this, though.

Does anyone know why this is so or how to get around it?

+4
source share
1 answer

Not sure if this is by design or error ... If you provide parameters, it works fine:

ActiveWorkbook.Protect ,true,true

or

ActiveWorkbook.Protect Structure:= true

What do you need / need. Thus, it will not disable protection, only on.

To disable protection, you can use this (if you only enabled structure protection):

ActiveWorkbook.Protect Structure:= false

Parameters:

.Protect(Password, Structure, Windows)
+3
source

Source: https://habr.com/ru/post/1628588/


All Articles