Workbook.Protect bug with toggling protection

475 views Asked by At

When I call Thisworkbook.Protect in VBA the protection of the workbook actually toggles from the current workbook's protection status instead of just protecting the workbook.

Thisworkbook.Unprotect doesn't do this though.

Anyone know why this is the case or how to get around it?

1

There are 1 answers

0
vacip On BEST ANSWER

Not sure if it is by design or a bug... If you provide the parameters, it works fine:

ActiveWorkbook.Protect ,true,true

or

ActiveWorkbook.Protect Structure:= true

Whichever you need/want. This way it won't turn the protection off, only on.

To turn the protection off, you can use this (assumning you only turned on structure protection):

ActiveWorkbook.Protect Structure:= false

Parameters are:

.Protect(Password, Structure, Windows)