1
votes

I'm hoping to restrict editing in a word document so that the users can only fill in forms. I have set the Restrict Editing option accordingly. However, depending on the options that are chosen in some of the combo boxes on the form, there is VBA code to add additional controls on the page. When I have the restriction turned on, the VBA that runs upon a certain selection will not run and throws a 'Command is not available' error. Is there a way to restrict everything but the content controls, toggle boxes, and combo boxes to the human users of the document, and allow the VBA code to operate freely, manipulating the format of the document without restrictions? Thanks for any help!

1

1 Answers

3
votes

Your macro will need to temporarily remove the protection so it can do its processing, then restore the protection afterwards. For example:

Dim lProt As Long: Const Pwd As String = "Password"
With ActiveDocument
  If .ProtectionType <> wdNoProtection Then
    lProt = .ProtectionType
    .Unprotect Password:=Pwd
  End If
  'insert your code for content control additions here
  If lProt <> wdNoProtection Then .Protect Type:=lProt, NoReset:=True, Password:=Pwd
End With