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 = "Test"
.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:
For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:
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 = "Test"
.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.