Word VBA Manage Editors RRS feed

  • Question

  • I have word template where I put some code to do the following:

    -control the "save" event to quit all editors

    -quit protection password -erase allowed editing areas

    -protect document from comments

    -save document

    -quit protection password

    -put again the editors pemissions areas

    -protect document again to continue working

    I do that to achieve this, if you open the document created with this template in a machine without this template you cannot edit the document. If you open the document in a machine with this template you can edit only some areas in the document. I control the "open" event and put the rights of editing in the document when is opened.

    the big question is this

    Sometimes the following method doesn´t work:


    this is annoying because sometimes the macro hangs. it sends me the message : "The requested member of the collection does not exist" debugging I realize the following:

    if you go to the "Protect Document" button in the ribbon and click manually the checked box "everyone" disable and enable it keeping the original value (enabled) then the method works fine!!

    I don´t know why this is happening, I tried to search the policy id for this checkbox for activate it using "Commandbars.findcontrol.execute" but i cannot find it in word documentation, perhaps i need to "enable" the use of this feature before used it, I don't know, somebody tried to do something similar?

    Thursday, July 10, 2014 5:03 PM


  • Unless the document created by the template has its own code to test for the presence of the attached template, this will never work. Even then, it will only work if the document is opened from a trusted location or the user allows your macro to run.

    Subject to the above, the required code for your purposes would be something like:

    Dim StrPwd As String, Rng As Range
    StrPwd ="Password"
    With ActiveDocument
      If .ProtectionType <> wdNoProtection Then .Unprotect Password:=StrPwd
      Set Rng = .Range.GoToEditableRange(wdEditorEveryone)
      Do Until Rng Is Nothing
        Set Rng = .Range.GoToEditableRange(wdEditorEveryone)
      .Protect Type:=wdAllowOnlyReading, Password:=StrPwd
    End With

    Paul Edstein
    [MS MVP - Word]

    Friday, July 11, 2014 1:30 AM