Microsoft KB Archive/181791

= Use a TextBox Form Control to work around 255 character limit in Word for Mac =

Article ID: 181791

Article Last Modified on 8/21/2007

-

APPLIES TO


 * Microsoft Word 2004 for Mac
 * Microsoft Word X for Mac
 * Microsoft Word 98 for Macintosh

-



This article was previously published under Q181791





SUMMARY
The Word FILLIN field prompts you for text that is used as the FILLIN field result. The maximum number of characters that can be entered in a FILLIN field is 255. In addition, the Microsoft Visual Basic for Applications InputBox statement is restricted to this 255 character limitation.

Microsoft Visual Basic for Applications allows you to construct a dialog box using the UserForm command. The form can contain text box controls into which you can type more than 255 characters. This article describes how to create and display the form.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements.

Creating the UserForm
Follow these steps to create the form:

 On the Tools menu, point to Macro, and then click Visual Basic Editor. In the Visual Basic project window, click Normal.

The form will be available to all documents. On the Insert menu, click UserForm. Click the TextBox control on the Toolbox toolbar, and then click the form.

The text box control appears in the default size. Drag a sizing handle to resize the control, or drag the control to move it to a new location. Click the CommandButton control on the Toolbox toolbar, and then click the form.

The command button appears in the default size. Drag a sizing handle to resize the control, or drag the control to move it to a new location.

Repeat this step to add a second CommandButton control. Select the first command button, and then click Code on the View menu.</li>  In the Code window, type Selection.TypeText TextBox1.Text, so your code looks like this: Private Sub CommandButton1_Click

Selection.TypeText TextBox1.Text

' When you click this button on the form, the contents of the ' text box are inserted into the active document at the location ' of the insertion point.

End Sub </li> On the View menu, click Object to return to the form.</li> Select the second CommandButton control, and then click Code on the View menu.</li>  In the Code window, type End, so your code looks like this: Private Sub CommandButton2_Click

End

' When you click this button after you click the first command ' button, the form is closed. If you click this button instead of         ' the first command button, the form is canceled.

End Sub </li> On the File menu, click Save Normal.</li></ol>

Displaying the Form
To display the form, switch to Word, and then follow these steps:

<ol> On the Tools menu, point to Macro, and then click Macros.</li> In the Macro Name box, type FillInForm, and then click Create.</li>  In the Code window, type UserForm1.Show, so your code looks like the following: Sub FillInForm UserForm1.Show End Sub </li> Save and close the macro.</li> Close the Visual Basic Editor.

You can now run the macro from Word to display the form.</li></ol>

If you want default text to appear in the text box, create the following Initialize event for the UserForm object. To do this, use the following steps:

<ol> Double-click the form.</li> In the Object list, click UserForm.</li> In the Procedure list, click Initialize.</li>  In the Code window, type the following code: Private Sub UserForm_Initialize TextBox1.Text = " " End Sub where is the text you want to appear in the text box when the form appears. </li></ol>

<div class="references_section">