Excel VBA: using dialog (xlDialogProtectDocument) .Show
I want to install Protect Sheet dialog in Excel. I want it to be installed like in this screenshot:
One way to open this dialog with some preconfiguration:
Application.Dialogs(xlDialogProtectDocument).Show arg1:=True
This sets / disables the first checkbox in the dialog.
According to the official documentation, the allowed arguments are:
contents, windows, password, objects, scenarios
In some trial versions and bugs not found how and how you can check the boxes in the lower list.
Is it possible? If so, how?
source to share
As noted in the comments in the comment, it recalls the previous parameter. This includes the settings used when setting up sheet protection via VBA. So setting + unprotecting with VBA before opening the dialog with
Application.ThisWorkbook.Sheets(1).Protect AllowFormattingCells:=True
Application.ThisWorkbook.Sheets(1).Unprotect
Application.Dialogs(xlDialogProtectDocument).Show
creates a checkbox as desired.
For a list of all possible method variations, .Protect
see the official documentation page.
This is an ugly solution as it has side effects (the leaf is soon protected in the process) and is based on side effects. For now, I will not accept this answer. Better answers are welcome and will be accepted.
source to share