How do I limit the text in a bookmark

J

Jens Thomsen

I put a bookmark in a cell in a table.
The cell has a standard width, can't get any wider.

How do I limit my bookmark to just one line of text?
Can I detect Cr or something.

All I want is one line of text in my bookmark and thats it.

Hope you can help me.

Jens, Denmark
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Set the cell height to a fixed value, then only one line of text will be
displayed.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
L

Lynn Taylor

You can use the following vba.

Dim sString As String
Dim iCount As Integer

sString = Selection.text
iCount = Selection.Characters.Count

If iCount > 10 Then
sString = Left(sString, 10)
End If
Selection.TypeText text:=sString
End Sub

Select the text in your bookmark, then run the code. It
counts the amount of characters in your string, and if
there are more than x amount, it just takes the first x
mount from the left and replaces the entire string with
just that amount of characters. You can change the
characters to words if you wish, so it will word.count.

The example above uses 10 characters but you can change
this to what you want.

Hope this is useful.
 
J

Jens Thomsen

Thanks!

But what I need to limit the amount of characters, dependign on the
cell.
The first answer did not help, it just did'nt display the rest of the
characters, if you continue to type, the bookmark get bigger but you
can't se it.

The second answer is not what I was looking for, this can also be done
under properties.

I need a function to catch a kind of keypress event and then calculate
how manny characters has been written, and how manny can be written.

When the bookmark is full (the width as the cell) no more characters
could be written.

I hope I did explain what I need, English is not my native language.

Jens Thomsen, Denmark
 
J

Jean-Guy Marcil

Hi Jens


Jens Thomsen said:
Thanks!

But what I need to limit the amount of characters, dependign on the
cell.
The first answer did not help, it just did'nt display the rest of the
characters, if you continue to type, the bookmark get bigger but you
can't se it.

So the user stops writing, thereby achieving the effect desired, no?
The second answer is not what I was looking for, this can also be done
under properties.

I need a function to catch a kind of keypress event and then calculate
how manny characters has been written, and how manny can be written.

When the bookmark is full (the width as the cell) no more characters
could be written.

The only way that you can practially and easily achieve that is by using a
fixed width font like Courrier. The problem is that space available and
number of characters depend on the charcters being used. Very dificult to
have code handle that. Consider "mummy" and "billions", mummy has 5
characters and billions has 8 characters, but is shorter. So use a fixed
width font and the field property to limit the number of character to the
space available. Otherwise, Doug,s solution is the one commonly used.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
M

Mark Baird

Regarding a question of this type, it may be helpful to know why are you trying to restrict the input from a user? I only ask so that we may determine if there is another approach that could be used

What problem are you trying to solve

Mark Baird
 

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