• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Show Unprotect dialog box in Excel VBA

Les Laplace

New Member
Hello All,

Can anyone help me with the macro code for Excel VBA to show the "Unprotect" dialog box?

When I use "Activesheet Unprotect" the unprotect dialog box to enter the password appears nicely, but when I use "ActiveSheet Protect" the dialog box does not appear allowing the password to be entered. I would have to include the "Password:="xxx" parameter. I would rather not hardcode a password in the macro code.

Appreciate any help.

Thanks,
Les.
 
Sorry, the first sentence should read "Can anyone help me with the macro code for Excel VBA to show the "Protect" dialog box?
 
The path to get information can be convoluted. You can print the list of controls using below code.
Code:
Sub ShowProtect()
Dim cmdBar As CommandBar
Dim ctrl As CommandBarControl
i = 1
For Each cmdBar In Application.CommandBars
Cells(i, "A").Value = cmdBar.Name
Cells(i, "B").Value = cmdBar.Index
i = i + 1
'    If cmdBar.Name = "Protection" Then
        For Each ctrl In cmdBar.Controls
            Cells(i, "C").Value = ctrl.Caption
            Cells(i, "D").Value = ctrl.Index
            i = i + 1
        Next ctrl
'    End If
Next cmdBar
End Sub
Once it is printed then you can invoke the correct item using syntax like below. For my computer, following syntax invokes Protect Sheet Dialog box.
Code:
Application.CommandBars(31).Controls(3).Execute
 
Last edited:
Wonderful, thanks a million Vletm, excellent information. I delved into it and found the following to show the protect sheet dialog:
Application.Dialogs(xlDialogProtectDocument).Show
Works like a charm.

Thanks.
 
Thanks shrivallabha, will try it out and let you know.


__________________________________________________________________
Mod edit : post moved to appropriate forum
 
Back
Top