View Single Post
  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default blocking specific text in Word

If you are using potected text form fields then you can validate those
fields for incorrect entry. The principles involved are described at
http://www.gmayor.com/formfieldmacros.htm .

To exclude words in a list, you can add code to the macros shown to validate
the content against a list of banned words e.g. in the following example the
list of banned words separated by commas is Const sList = "Tea,Coffee,Cocoa"

The macro will filter out those words and require the user to re-enter a
value in the field that is not banned.

If the list of allowed expressions is less than 25, you can use a dropdown
field instead (as suggested by Suzanne) which will eliminate the need for
the macros.

If the list is longer than 25 items and you wish to select from a list, you
will need a userform. See instead
http://gregmaxey.mvps.org/FormField_...rm_ListBox.htm

Option Explicit
Private mstrFF As String
Private sBarred() As String
Private i As Long
Const sList = "Tea,Coffee,Cocoa"
Private Sub AOnExit()
sBarred = Split(sList, Chr(44))
With GetCurrentFF
mstrFF = .name
If Len(.Result) = 0 Then
MsgBox "You can't leave field: " _
& .name & " blank"
End If
For i = 0 To UBound(sBarred)
If InStr(1, .Result, LCase(sBarred(i))) = 1 Then
MsgBox "You cannot use " & sBarred(i)
Exit For
End If
Next i
End With
End Sub

Private Sub AOnEntry()
sBarred = Split(sList, Chr(44))
'Goto another FormField if we weren't supposed to leave it!
For i = 0 To UBound(sBarred)
If InStr(1, ActiveDocument.FormFields(mstrFF).Result, _
LCase(sBarred(i))) = 1 Then
ActiveDocument.FormFields(mstrFF).Select
Exit For
End If
Next i

If Len(ActiveDocument.FormFields(mstrFF).Result) = 0 Then
ActiveDocument.FormFields(mstrFF).Select
End If
mstrFF = vbNullString
End Sub

Private Function GetCurrentFF() As Word.FormField
Dim rngFF As Word.Range
Dim fldFF As Word.FormField
Set rngFF = Selection.Range
rngFF.Expand wdParagraph
For Each fldFF In rngFF.FormFields
Set GetCurrentFF = fldFF
Exit For
Next
End Function

http://www.gmayor.com/installing_macro.htm

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



"Tammy" wrote in message
...
Hello-
I am creating a document for a client. There will be certain areas that
will
be locked and certain areas where my client will need to input
information.
They wanted to know if there is a way that when their team types in their
information that they can block out specific words so they wouldn't be
able
to type them in.
For example, they have a long list of products and only want the client to
be able to input certain product words but block out other ones. Is there
anyway to do this?
Thanks!