Starbird was telling us:
Starbird nous racontait que :
I have built a template that is protected to allow filling in form
fields. Is it possible to allow the user to select styles to apply to
their text when they fill in a text field? If so, how would I go
about that?
Here is some code I have used to allow bold/italic/underlining in form
fields before. I built a toolbar and assign the Sel_Bold etc. to buttons on
the toolbar. I think you can easily adapt this to applying styles instead.
Just keep in mind that styles affect the whole paragraph, not only the user
selection.
'_______________________________________
Public myRange As Range
'_______________________________________
Sub Sel_Bold()
Sel_Unprotect
myRange.Bold = wdToggle
Sel_Protect
End Sub
'_______________________________________
'_______________________________________
Sub Sel_Italic()
Sel_Unprotect
myRange.Italic = wdToggle
Sel_Protect
End Sub
'_______________________________________
'_______________________________________
Sub Sel_Underline()
Sel_Unprotect
If myRange.Underline = wdUnderlineNone Then
myRange.Underline = wdUnderlineSingle
Else
myRange.Underline = wdUnderlineNone
End If
Sel_Protect
End Sub
'_______________________________________
'_______________________________________
Sub Sel_Unprotect()
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=""
End If
Set myRange = Selection.Range
End Sub
'_______________________________________
'_______________________________________
Sub Sel_Protect()
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, _
Password:=""
End If
myRange.Select
End Sub
'_______________________________________
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org