ContentControl.LockContents with document protection

S

Simon Svensson

Hello.

I'm executing a macro in a document with an active document protection that
only allow form editing. The macro works as expected when document protection
is disabled, but will always cause the control to be readonly when the
document is protected.

Reproduce:
1) Create a new macro-enabled document (docm), add a content control of type
text and an normal button from the dropdown of controls from earlier controls.
2) Edit the macro for the onclick event of the button to the following:

ActiveDocument.ContentControls(1).LockContents = _
ActiveDocument.ContentControls(1).LockContents

3) Change the content of the content control. It should work.
4) Click the button and try and edit the content. It should work.
5) Apply document protection using "Only allow these edits: Edit forms"
6) Verify that editing the content control works.
7) Press the button.

Editing of the content control should now work, but it doesnt. I get a
keyboard cursor and can select text, but typing anything on the keyboard wont
change the content of the control. No notice is shown about changes not being
allowed due to a locked control.

13) Disabled the document protection, but dont click the button.
14) Editing works again.

To summarize; setting a custom controls LockContents via a macro when
document protection that only allows form editing is activated will always
cause the custom control to be readonly. It doesnt matter what value I give
to LockContents.

Any thoughts? Solutions?

Thanks.
Simon Svensson
 
J

Jay Freedman

My thought is that you shouldn't mix content controls with forms protection.
The forms protection is meant to be used with the legacy forms controls
(that is, the form fields that existed in Word 2003 and earlier).

To achieve a similar functionality with only content controls:

- Insert the content controls that you want the user to fill, plus any
surrounding text/graphics.
- Select the entire document body.
- Insert a Rich Text content control, which now contains the entire
document.
- Set the properties of the Rich Text content control to "Do not allow
editing" and "Do not allow deletion".

The embedded content controls will function as desired (in effect, they're
the "form fields"), and everything else in the document will not be editable
(it's "protected").

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
S

Simon Svensson

Is there no solution that wont bring a big semi-fluid bluish box around all
my content?

1) Content control isnt locked down when document protection applies.
2) LockContents works as expected out of document protection.
3) LockContents will cause lockdown when in document protection.

Editing of control controls when document protection is in place should
depend on allowing form edits and LockContents=false. The behavior of
allowing form edits, but locking down the control even when I set
LockContents=false suggest to me that this is a behavior fault in the Word
2007 engine.

If document protection is in place and wont allow me to edit my content
control, why wont it limit macros that does it?

Surely there must be some way to write templates with content controls and
document protection without wrapping everything in a rtf control? Using a rtf
content control sounds just like an quick hack for something that isnt
working as it should.

Is there any place I can report this as a bug, and at least see if it is
something that actually is a bug, or if it is actually working as intended
(in a way that doesnt follow the thoughts of a normal user, according to me)?

// Simon Svensson
 

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