Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

auto resize text to fit in fixed size text box using word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
monnyjartin - 04 Oct 2006 14:19 GMT
I have a document that inputs text from a word VBA form into a text
box.

This is done by using a bookmark placed in the text box then running
the following command

.Bookmarks("part1").Range.Text = txtpt1.Value

The problem I have sometimes the text is too small for the text box and
other times it is too big so once my code has finished running the user
has to manually resize the text font size to fit the text box.

Is there a way i.e. VBA code that will auto resize the text to fit the
size of the text box

Many thanks

Monnyjartin
jille - 05 Oct 2006 15:14 GMT
I did something like this once for a client a very long time ago, so the code
isn't wonderful but it did the trick...

When they clicked a particular formfield, I had a small dialog box appear to
enter the text and wrote the following code behind the OK button. I had
already figured out what number of characters normally fit into the area so
if the text exceeded this limit, I reduced it's size.
"FrmBriefDescriptionOfLand" is the name of the userform, and
"txtBriefDescriptionOfLand" is the text control in the userform.

If FrmBriefDescriptionOfLand.TxtBriefDescriptionOfLand.TextLength > 281 Then
With Selection.Paragraphs(1).Range.Font
      .Size = 8
   End With
End If

Hope this helps,

JillE

> I have a document that inputs text from a word VBA form into a text
> box.
[quoted text clipped - 14 lines]
>
> Monnyjartin
JCNZ - 22 Oct 2006 09:55 GMT
Hi:

After you have written the text into the textbox, you could try:

Sub AA()
   With ActiveDocument.Shapes(X).TextFrame
       Do
           .TextRange.Font.Shrink
       Loop While .Overflowing
   End With
End Sub

- where shapes(X) is your textbox.

If you give the textbox a name:

ActiveDocument.Shapes(X).Name="Fred"

- then you can say:

Sub AA()
   With ActiveDocument.Shapes("Fred").TextFrame
       Do
           .TextRange.Font.Shrink
       Loop While .Overflowing
   End With
End Sub

> I have a document that inputs text from a word VBA form into a text
> box.
[quoted text clipped - 14 lines]
>
> Monnyjartin
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.