Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1753
  • Last Modified:

MS Word - Autosize Font in Text Boxes

Hello, MS Word experts. Let's say I create a text box that is defined with a specific textbox size (say 2" x 1") and a specific font size (say 12pt).

Is there a way to make that text box's font automatically decrease to fit the 2"x1" so the text, if it's longer than 2", is fully seen in the box? I, basically, don't want to have to make the box bigger if there is text in it that doesn't fit the initial sizes.

I'm asking because I want to send text to a text box from a .NET program and the text that gets sent may be longer than the specified dimensions of the textbox.

Thanks!
0
infotechelg
Asked:
infotechelg
  • 5
  • 3
1 Solution
 
KimputerCommented:
Probably something along the line of:
Private Sub TextBox1_Change()
If Len(TextBox1.Text) > 10 Then
    TextBox1.Font.Size = 5
Else
    TextBox1.Font.Size = 20
End If
End Sub

Open in new window

You need to do the tweaking, as in, decide lenght of text, and fontsize. Maybe add more case or ifs.
0
 
infotechelgAuthor Commented:
This is a macro, then, in Word?
0
 
KimputerCommented:
Officially, it's not a macro perse, as those are things you run manually. This one is more Event driven (it changes while you type in the textbox), but you have to put it in the same spot (ALT+F11 to open VBA editor)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
infotechelgAuthor Commented:
But I will not be typing in the textbox. .NET is going to populate a text box with text. Will it still work?
0
 
infotechelgAuthor Commented:
I don't think this is going to work for me. I find it hard to believe there's no option in Word for text to fit into the confined space of a textbox. It seems like something that would be a common request.
0
 
KimputerCommented:
This code works as long as there are changes made to the textbox. That could be typing, but automated population should also work.
The properties for a textbox are all layed out before you. There are no secret properties that allow you to automatically adjust the font, not even in the Visual Basic 2010 edition (more advanced than Words VBA Textbox).
0
 
infotechelgAuthor Commented:
I ended up handling this in the .NET code. Hopefully, MS will add this feature sometime in the future.
0
 
infotechelgAuthor Commented:
Went a different route.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now