Microsoft KB Archive/289018

= PUB2002: Cannot Programmatically Fit Text into a Text Box =

Article ID: 289018

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Publisher 2002 Standard Edition

-



This article was previously published under Q289018





SYMPTOMS
In Microsoft Publisher, when you write a Microsoft Visual Basic for Applications macro that creates a text box and fits text into the text box, the macro does not function as expected. The text is inserted into the text box in the default font size instead of filling the text box.

This behavior occurs even though the text box size is valid.



CAUSE
This problem occurs when you use a Visual basic for Applications macro to create a text frame and then enter text into the text frame, as in the following sample code: Sub test With ThisDocument.Pages(1).Shapes.AddTextbox(pbTextOrientationHorizontal, 100, 100, 100, 100) .TextFrame.TextRange.Text = &quot;Test&quot; .TextFrame.AutoFitText = pbTextAutoFitBestFit End With End Sub The text will not change size to fit the text frame until something refreshes the text box and text.



RESOLUTION
To resolve this problem, either add a line to the macro that refreshes the text frame, or manually adjust the size of the text frame so that the text will refresh and fill the text frame.

Method 1: Macro
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

A simple line that adjusts the size of the text frame, without really changing the text frame is the following: .Height = .Height The following sample code demonstrates how to use this line of code: Sub test With ThisDocument.Pages(1).Shapes.AddTextbox(pbTextOrientationHorizontal, 100, 100, 100, 100) .TextFrame.TextRange.Text = &quot;Test&quot; .TextFrame.AutoFitText = pbTextAutoFitBestFit .Height = .Height End With End Sub

Method 2: Manually Refresh
You can also force the text to refresh and fill the text box by manually changing the size or of the text frame or slightly moving the text frame with the grab handles.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

212536 OFF2000: How to Run Sample Code from Knowledge Base Articles

Additional query words: prb

Keywords: kbbug kbpending KB289018

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.