VBA - creating TextBox with MaxLength value?

G

Geoff Cox

Hello,

The code below adds a TextBox (the kind obtained using Control
ToolBox) with the same size and position as the Text Box (as drawing a
shape from the bottom toolbar of PPT and adding a word to it) which it
replaces.

How can I make the MaxLength either a fixed number of characters or
better still large enough to take the varying size of the words in the
Text Boxes?

For the second I need to count the number of characters in each text
box - hints as to how to do this?!

Cheers

Geoff


With oSl.Shapes
..AddOLEObject _
Left:=posLeft, _
Top:=posTop, _
Height:=posHeight, _
Width:=posWidth, _
ClassName:="Forms.TextBox.1", _
Link:=msoFalse
End With
 
B

Bill Dilworth

I would insert a textbox control using the control toolbox. Then use this
code of the slide's code page...

'Fixed Character length
Private Sub TextBox1_Change()
With TextBox1
If .TextLength > 15 Then
.Text = Left(.Text, 15)
End If
End With
End Sub


The method for limiting the length in width is somewhat more complicated.


--
Bill Dilworth
A proud member of the Microsoft PPT MVP Team
Users helping fellow users.
http://billdilworth.mvps.org
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
vestprog2@ Please read the PowerPoint FAQ pages.
yahoo. They answer most of our questions.
com www.pptfaq.com
..
 
G

Geoff Cox

I would insert a textbox control using the control toolbox. Then use this
code of the slide's code page...

'Fixed Character length
Private Sub TextBox1_Change()
With TextBox1
If .TextLength > 15 Then
.Text = Left(.Text, 15)
End If
End With
End Sub


The method for limiting the length in width is somewhat more complicated.

Bill,

Perhaps I ought to have given the full context.

I have lots of presentations which each have multiple Text Boxes which
have entrance/dissolve animation. The idea is to replace each of those
with a TextBox Control which is big enough for the user to type in the
same word as was in the Text Box.

(Incidentally I hope I am making clear the distinction between the
Text Box (Text Box) which was drawn using the icon on the bottom tool
bar of PowwerPoint and then text was added to it, and the TextBox
(TextBox Control) which can be added using the Control Toolbox.)

So far the code I have written adds a TextBox Control with the same
position and dimensions as the original Text Box and gives a MaxLength
of 100 characters. (the values for left etc come from the code further
down the page)

Set OTextBox = oSl.Shapes.AddOLEObject( _
Left:=posLeft, _
Top:=posTop, _
Height:=posHeight, _
Width:=posWidth, _
ClassName:="Forms.TextBox.1", _
Link:=msoFalse)

With OTextBox.OLEFormat.Object
..MultiLine = True
..WordWrap = True
..MaxLength = 100
End With

It would be better if I could get the number of characters of the
words in each original Text Box (adding perhaps 10 for safety) and
then use this figure for the different MaxLength values.

I can recognise the original Text Boxes using the code below - any
idea how I would get the number of characters in the Text Box?

Cheers

Geoff

If .MainSequence(I).shape.Type = msoTextBox Then
On Error Resume Next
If .MainSequence(I).shape.AnimationSettings.EntryEffect _
= ppEffectDissolve Then

posLeft = .MainSequence(I).shape.Left
posTop = .MainSequence(I).shape.Top
posWidth = .MainSequence(I).shape.Width
posHeight = .MainSequence(I).shape.Height
 
G

Geoff Cox

On Sun, 17 Dec 2006 23:01:06 -0500, "Bill Dilworth"

Bill

A step forward!

Code below finds the number of characters in word/s in the Text Box.

Cheers

Geoff

With .MainSequence(I).shape
If .HasTextFrame Then
If .TextFrame.HasText Then
Words = .TextFrame.TextRange.Words
numChrs = Len(Words)
End If
End If
End With
 

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