FIxed number of words in a cell or text box

H

Harry Hudini

Is there a way that you can tell word to limit the number of words in a cell
or a textbox ?

We have a template that is used to send an advert to the printers, and the
users that fill it out are ALWAYS going over the number of words allowed,
which costs us money.

I am looking for a way to limit the user so that they can only enter the
correct number of words ?

Olly

--
________________________________________________
ADSSupport.net
http://www.adssupport.net
Dedicated free Active Directory ServicesT support

email: oliver.marshall@[email protected]
 
S

Suzanne S. Barnhill

You can limit the number of characters in a text form field. You can limit
the size of a table cell or text box.
 
J

Jay Freedman

Hi, Olly,

I don't know of any way to prevent people from typing any number of
words into a cell, but you can prevent them from saving or printing
the document while there are too many words. That might solve your
problem.

To do this, you need a series of macros in the template used to base
the documents. Each macro needs a specific name that will cause it to
intercept one of Word's built-in commands -- File > Print, File >
Save, File > Save As, and so on. To intercept the Print commands you
need to write FilePrint and FilePrintDefault. To intercept the Save
commands you need to write FileSave, FileSaveAs and FileSaveAll.
There's more about this at
http://word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm.

As an example, the macro for FileSaveAs would look something like this
(but adjusted for the table number and row/column as necessary):

Public Sub FileSaveAs()
Const MaxWords = 60 ' change as needed
Dim CountWords As Long
Dim CellRange As Range

' if there are no tables, don't test
If ActiveDocument.Tables.Count > 0 Then
' check the cell in row 1, column 2 of
' the first table in the document
' (change this as needed)
Set CellRange = ActiveDocument.Tables(1) _
.Cell(Row:=1, Column:=2).Range

' don't include the end-of-cell marker
CellRange.MoveEnd unit:=wdCharacter, Count:=-1

' get the number of words
CountWords = CellRange.ComputeStatistics(wdStatisticWords)

' if too many, refuse to save
If CountWords > MaxWords Then
MsgBox "The cell contains " & CountWords & _
" words. The maximum is " & MaxWords & _
" words."
Exit Sub
End If
End If

' It passed the test, so save
Dialogs(wdDialogFileSaveAs).Show
End Sub
 

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