How to Create a Microsoft Word Form That Auto Hides Text When Checkbox Is Checked?
By Darrin Koltow
By learning to hide text when a Word form's checkbox is checked, you can let form users control large amounts of content in a document with a single click. The event function of Word's Visual Basic programming language makes this project possible. Event functions are functions that Word executes whenever a user interacts with a form control linked to your program. For example, the event function "Checkbox1_Clicked" will run when a user clicks the checkbox named "CheckBox1."
Click the "File" menu's "New" command, then click "OK" to accept the default parameters for a new document. Click the "Developer" tab to display the "Controls" panel, which contains controls you can insert on your form.
Click any control you'd like for the form, such as a text box or dropdown list. Word will add the controls you click to the form.
Click the "Checkbox" control to add this control to the form, then type some text below the form. You'll write a program for the checkbox control that will hide this text.
Drag the mouse over the text to select it, then click the "Insert" tab's "Bookmark" button. Type the name "TextToHide" for the bookmark, then click "Add" to link this name with the bookmark. This step names the bookmark so your program can easily identify which text to hide.
Right click the checkbox control, and click the "View code" item to open the Visual Basic environment in which you'll write a program for the checkbox.
Paste the following program into the window. This program reads the "Hidden" property of the text you bookmarked. If that property is set to "False," the text is not yet hidden. The program will set this property to true, which will hide the text.
Private Sub CheckBox1_Click()
If Bookmarks("TextToHide").Range.Font.Hidden = True Then
Bookmarks("TextToHide").Range.Font.Hidden = False
Bookmarks("TextToHide").Range.Font.Hidden = True
Click the "Word" icon on the Windows taskbar to return to your Word form, then click the "Design mode" button of the "Developer" tab to activate the form for data entry.
Click the checkbox. This action will run your program, which will hide the text you bookmarked. Click the checkbox again to reveal the text.
- "Microsoft Word Bible"; Herb Tyson; 2010
- "Mastering VBA for Office 2010"; Richard Mansfield; 2010
Darrin Koltow wrote about computer software until graphics programs reawakened his lifelong passion of becoming a master designer and draftsman. He has now committed to acquiring the training for a position designing characters, creatures and environments for video games, movies and other entertainment media.