Frank was telling us:
Frank nous racontait que :
Hi Charles,
I know the Exit Macro doesn't work. Any idea what script to run after
exit the formfield description so the template is protected again.
Instead of removing the protection when entering a field, you could give
your users the possibility of changing font attributes in all formfields.
Check out the sample code below. Create a toolbar (Or assign the font
attribute to the actual button on the Format toolbar - Add the macro the
Format toolbar, right click the Standard Bold button, "Copy Button Image",
then right click the button you created and right-click to paste the button
image, make the face "Default" - not text, remove the Word Bold button form
the Format toolbar. Of course, this will work best from a template.)
'_______________________________________
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
'_______________________________________
If you want to allow this type of editing in specific field, check the value
of the selected formfield name, and allow editing or not based on this.
See this code variation:
'_______________________________________
Public myRange As Range
'_______________________________________
Sub Sel_Bold()
If Sel_Unprotect Then
myRange.Bold = wdToggle
Sel_Protect
End If
End Sub
'_______________________________________
Sub Sel_Italic()
If Sel_Unprotect Then
myRange.Italic = wdToggle
Sel_Protect
End If
End Sub
'_______________________________________
Sub Sel_Underline()
If Sel_Unprotect Then
If myRange.Underline = wdUnderlineNone Then
myRange.Underline = wdUnderlineSingle
Else
myRange.Underline = wdUnderlineNone
End If
Sel_Protect
End If
End Sub
'_______________________________________
Function Sel_Unprotect() As Boolean
Sel_Unprotect = True
Select Case ActiveDocument.FormFields(Selection.BookmarkID).Name
Case "NoEdit", "OtherName", "ManyNames", _
"StillAnotherField", "Etc"
MsgBox "You cannot modify font attributes in this field.", _
vbExclamation, "No font editing"
Sel_Unprotect = False
Exit Function
Case Else
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=""
End If
Set myRange = Selection.Range
End Select
End Function
'_______________________________________
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