Maximum width of text within VBA textbox control

  • Thread starter Thread starter Allen Johnson
  • Start date Start date
A

Allen Johnson

Does anyone have a method to find the maximum width of text within a VBA
multiline text box?
I'd like something to find the longest line of text of a note such as:

8" CONCRETE CAP SLAB
REINFORCE W/ #5 @ 8" O.C. EA WAY
ELEVATION TOP SLAB 108-0

The only property I can find is the .CurX Property.
VB has the .Textwidth method, but it doesn't appear to exist in VBA.

The reason is I'd like to size the textbox control to be fairly
representative of the maximum length of the longest line within the textbox
control.
 
Good idea! Thanks.

With txtNotes
.AutoSize = True
.Text = TextString
tbw = .Width
.AutoSize = False
.Width = 1.2 * tbw
.Left = (Me.Width - .Width) / 2
.Height = 95
End With
 
You're welcome. Another FYI, might be to calulate it from the width of a
char (in points), multiplied by the LEN of the widest string. Although I
think you've got the easier way.
 
Don't forget to resize your form to fit your resized textbox. Sooner or later you will be resizing other items and then you may run into the frustrating problem of your newly calculated resized objects not always updating to the resized dimension.
 
Back
Top