Article ID: 212717
Article Last Modified on 10/11/2006
APPLIES TO
- Microsoft Word 2000 Standard Edition
This article was previously published under Q212717
SUMMARY
The Microsoft Word FILLIN field prompts you for text that is used as the field value. 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 a TextBox control into which you can type more than 255 characters. This article describes how to create and display the user 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 User Form
Create the form using the following steps:
- On the Tools menu, point to Macro, and then click Visual Basic Editor. Alternatively, press ALT+F11 in Word to start the Visual Basic Editor.
- In the Visual Basic Project window, click Normal.
(This allows the form to 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 TextBox 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.
- Press F4. On the Properties menu, select EnterKeyBehavior set to True, and then select MultiLine set to True.
- Click the CommandButton control on the Toolbox toolbar, and then click the form.
The CommandButton 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.
Repeat this step to add a second CommandButton control. - Select the first CommandButton control, and then click Code on the View menu.
In the Code window, type
Selection.TypeText TextBox1.Text
so that 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 is inserted into the active document at the location of the 'insertion point. End sub
- On the View menu, click Object to return to the form.
- Select the second CommandButton control, and then click Code on the View menu.
In the Code window, type
End
so that 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
- On the File menu, click Save Normal, and then press ALT+F4 to close the Visual Basic Editor.
Displaying the Form
To display the form, switch to Word, and then do the following:
- On the Tools menu, point to Macro, and then click Macros.
- In the Macro name box, type
FillInForm
and then click Create. In the Code window, type
UserForm1.Show
so that your code looks like this:Sub FillInForm() UserForm1.Show End Sub
- Save and close the macro.
- Close the Visual Basic Editor.
- You can now run the macro from Word to display the form.
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:
- Double-click the form.
- From the Object drop-down list, select UserForm.
- From the Procedure drop-down list, select Initialize.
In the Code window, type the following code
Private Sub UserForm_Initialize() TextBox1.Text = "<default text>" End Sub
where <default text> is the text you want to appear in the text box when the form appears.
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
212536 How to run sample code from Knowledge Base articles in Office 2000
REFERENCES
For more information about getting help with Visual Basic for Applications, click the following article number to view the article in the Microsoft Knowledge Base:
226118 List of resources that are available to help you learn Visual Basic for Applications programming
Additional query words: vb vba vbe
Keywords: kbhowto kbmacroexample kbprogramming kbusage KB212717