Disable "Unprotect Document" in Tools Menu Item

Is it possible to disable "Unprotect Document" in Tools Menu Item in MS Word using VBA

We are accessing and modifying documents in Java using JACOB. If the document is protected we are unprotecting the document and doing modifications. But if the document is protected using a password there is no way we can provide the password programatically as each document could have different passwords.

So if it is possible to disable the "Unprotect Document" menu using VBA then the menu can be disabled and the document protected without password. This way the document can be accessed and modified only programatically and not by the user.



Answer this question

Disable "Unprotect Document" in Tools Menu Item

  • Jimmy7777

    Thank You very much for the solution. I will try it out and let you know the status.


  • Scottcha

    It worked fine I was able to disable the menu items from Java using JACOB.


  • Keith Organ

    Hi Veera

    There are a number of ways of doing this, but I've found the following easier to understand, but it does have the disadvantage that it is language specific.

    You also might want to look at disabling the Customise command so users can't enable the command again. However, you might want to make sure you have an easy way to enable it again.

    Then there is also the Protect Form button on the Forms commandbar ...

    Regards

    Peter Mo.

    Sub DisableProtect()
    If CBControlEnableStr("Tools", "&Protect Document...", False) Then
    MsgBox "Success"
    Else
    MsgBox "Failed"
    End If
    End Sub

    Sub DisableUnprotect()
    If CBControlEnableStr("Tools", "Un&protect Document", False) Then
    MsgBox "Success"
    Else
    MsgBox "Failed"
    End If
    End Sub

    Function CBControlEnableStr(cbName As String, _
    controlName As String, _
    controlEnable As Boolean) As Boolean
    CBControlEnableStr = True
    On Error Resume Next
    Word.Application.CommandBars(cbName).Controls(controlName).Enabled _
    = controlEnable
    If Err.Number <> 0 Then CBControlEnableStr = False
    End Function


  • Disable "Unprotect Document" in Tools Menu Item