Editing Restrictions and VBA

D

dsimcox

I have some form fields on a Word 2003 document. Unless the document is
protected, the form fields are not functional (I can't check a check box when
the document is unprotected)

I have a simple VBA procedure that toggles document protection, and when
protection is ON, the form fields work.

I've converted the document to Word 2007. Now this process is broken. In
order to make the form fields work, not only does the document need to be
protected, but I also have to do these 3 steps:
+
1. use the Editing Restrictions feature, click the "Allow only this type of
editing in the document" checkbox, then

2. select the tables containing the form fields (to identify the areas
where editing is allowed), and finally,

3. click the "Yes, Start Enforcing Protection" button

Then, the document is protected, and the form fields are editable.

BUT, if I remove the protection (I do this with a VBA procedure), the
re-apply the protection again, the form fields STOP working.

I have to go back manually and accomplish steps 1, 2, and 3.

I want to be able to do this with VBA so I can toggle this behavior with the
click of a button.

I've tried recording a macro to capture the code, but the macro recorder
does not capture these events for some reason.

Can someone direct me to a resource that will help me identify the objects
in the Restrict Editing and Formating pane so that I can manipulate them via
VBA?
 
J

Jay Freedman

I have some form fields on a Word 2003 document. Unless the document is
protected, the form fields are not functional (I can't check a check box when
the document is unprotected)

I have a simple VBA procedure that toggles document protection, and when
protection is ON, the form fields work.

I've converted the document to Word 2007. Now this process is broken. In
order to make the form fields work, not only does the document need to be
protected, but I also have to do these 3 steps:
+
1. use the Editing Restrictions feature, click the "Allow only this type of
editing in the document" checkbox, then

2. select the tables containing the form fields (to identify the areas
where editing is allowed), and finally,

3. click the "Yes, Start Enforcing Protection" button

Then, the document is protected, and the form fields are editable.

BUT, if I remove the protection (I do this with a VBA procedure), the
re-apply the protection again, the form fields STOP working.

I have to go back manually and accomplish steps 1, 2, and 3.

I want to be able to do this with VBA so I can toggle this behavior with the
click of a button.

I've tried recording a macro to capture the code, but the macro recorder
does not capture these events for some reason.

Can someone direct me to a resource that will help me identify the objects
in the Restrict Editing and Formating pane so that I can manipulate them via
VBA?

None of that should be necessary. Since you didn't show any of the code you're
using, I can't guess what you're doing wrong, but code like this will work in
both 2003 and 2007:

If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If

' do whatever needs to be done while unprotected

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

If the document has a password for the protection, you'll need to include the
optional Password argument in both the Unprotect and Protect commands.
 
D

dsimcox

Excellent! Thanks for responding, Jay.

Specifying the correct Protection Type solved the problem. Here's the
simple code I used to toggle protection and retain editable form fields:

===============================================
Public Sub ToggleProtect()

If ActiveDocument.ProtectionType = wdNoProtection Then

ActiveDocument.Protect Password:="xxxxxx", NoReset:=True, Type:= _
wdAllowOnlyFormFields, UseIRM:=False, EnforceStyleLock:=False
Else:
ActiveDocument.Unprotect Password:="xxxxxx"

End If

End Sub

==================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top