Setting limits on word counts

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I limit the amount of words allowed in a section of text?

I am creating a template that incudes a space for abstracts. I need to
limit that section to only 150 words. Is that possible?
 
You can't force it, no. You could set up a fixed size table cell to contain
the abstract, such that more than a reasonable quantity of text will
overflow it.
 
There isn't any VBA that I can use to count the words and stop when that is
reached?
 
Not really. You can certainly use VBA to count the words in a part of the
document and do something if a limit is reached; but you can't (easily) have
VBA running while you type. Nor can you force the user to take notice of
VBA's messages. NOr indeed can you force the user to permit the VBA to run
at all.

In practice a polite request: "please do not go over 150 words" will be just
as effective, and much less work.
 
Okay......what is the coding to count the words in a certain section. I
could create an icon or button in the document so that they can keep track
themselves without having to manually count the words in the abstract. It
could even display a message when they count and it is over the limit. It is
more to assist the student by using the template. They are not being forced
to use it. Your advice is greatly appreciated.
 
The following gives a count of the words in the body of Section 1.
ActiveDocument.Sections(1).Range.Words.Count

--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
A single row single column borderless table might be a good place to
put your abstract text. Maybe you could adapt the following to suit
your specific needs:

Sub WordClip()
Dim oTbl As Table
Dim tmpRng As Range
Set oTbl = ActiveDocument.Tables(1)
If oTbl.Cell(1, 1).Range.Words.Count > 150 Then
MsgBox "Abstract entry exceeds word limit and will be trucated."
Do While oTbl.Cell(3, 1).Range.Words.Count > 151
Set tmpRng = oTbl.Cell(3, 1).Range.Duplicate
tmpRng.End = tmpRng.End - 1
tmpRng.Words.Last.Delete
Loop
oTbl.Cell(3, 1).Range.Text = tmpRng.Text
End If
End Sub
 
I will try both Charles and Greg's suggestions and let you know what I decide
 

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

Back
Top