View Single Post
  #7   Report Post  
Jay Freedman
 
Posts: n/a
Default

On Mon, 10 Jan 2005 04:27:02 -0800, AnttiK antti.koksalo( at
)vamp.fi wrote:

"Jezebel" kirjoitti:
It's called a "form", well documented in help.

Where your question becomes challenging is the issue of *preventing* users
screwing up your document. If you can assume that your users have no
malicious intent, there's no problem -- create a form in the usual way and
simply *ask* them not to muck around with it. Not even worth posting a
question about... just follow the examples in Help.

If you can't make that assumption you need to be *very* specific about what
you're trying to achieve.'Allowed' in the sense that getting it wrong will
literally kill people? -- (which is the case with some kinds of
documentation.)


We are already using forms. Unfortunately we cannot make the assumption that
the layout of the document will stay untouched, therefore we must protect it
from such changes. We are trying to allow only the use of four or five
different styles inside the text form fields. For some reason after
protecting the document, no styles are selectable by the user. This is
strange since the "1. Formatting restrictions" section of the protect
document gives the idea of being able to choose from certain styles. Are we
misunderstanding something, or is there another way of handling the issue?

-Antti


Hi Antti,

I assume you're working with Word 2003, since the formatting
restrictions first appeared in that version. The following method
works in all versions back to Word 2000 (maybe 97, I'm not sure)
because it doesn't depend on the restriction -- it's just that your
template will supply the only methods of changing the style in text
fields, and you supply only the styles you want.

When the form is protected, Word disables all methods of changing the
style, through dialogs, shortcuts, and VBA. The solution is to use VBA
to unprotect the document, change the style, and then restore the
protection, all in one operation.

You can place macros like these in your template (you may need to
change the names of the styles, as these aren't constant from one
language version to another). Also create toolbar buttons and/or
keyboard shortcuts to make it easy to call the macros.

Sub FieldStyleNormal()
Dim SaveRange As Range
Set SaveRange = Selection.Range
ActiveDocument.Unprotect
Selection.Paragraphs(1).Range.Style = _
ActiveDocument.Styles("Normal")
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True
SaveRange.Select
End Sub

Sub FieldStyleHead1()
Dim SaveRange As Range
Set SaveRange = Selection.Range
ActiveDocument.Unprotect
Selection.Paragraphs(1).Range.Style = _
ActiveDocument.Styles("Heading 1")
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True
SaveRange.Select
End Sub

Sub FieldStyleHead2()
Dim SaveRange As Range
Set SaveRange = Selection.Range
ActiveDocument.Unprotect
Selection.Paragraphs(1).Range.Style = _
ActiveDocument.Styles("Heading 2")
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True
SaveRange.Select
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org