Chapter 5. Managing Macros and Forms

In this chapter, you will work with commands in the Code and Controls groups on the Developer tab. You will learn how to record and run a macro, which lets you automate the steps involved in repetitive and common tasks. You’ll also learn how to work with controls such as list boxes and date pickers and how you can use them to create a form.

Important

If the Developer tab is not displayed on the ribbon, open the Word Options dialog box from the File tab, click Customize Ribbon, and then select Developer in the list of main tabs.

5.1 Apply and Manipulate Macros

A macro is a procedure written in the Microsoft Visual Basic for Applications programming language (also known as VBA). A procedure is a series of instructions that are saved as a unit and can then be performed as a single instruction. In Microsoft Word, for example, you can record a series of commands or keystrokes as a macro. You can run the macro when you need to complete the steps again later in the same document or in other documents you create.

Some of the operations you might use in a macro include the following:

  • Applying styles

  • Changing page layout settings

  • Changing view or zoom settings

  • Entering or deleting text

  • Navigating a document

  • Opening dialog boxes and setting dialog box options

  • Resizing embedded images

  • Saving or opening files

  • Selecting text

Using the Macro Recorder

If you are familiar with the VBA programming language, you can write the code for a macro yourself. If you aren’t a programmer or you want to get a start on a macro you are writing, you can record the steps you want a macro to perform. Word generates the code for you, and you can then run the macro when you need it.

Before you record a macro, it’s helpful to rehearse. Follow the steps you want to capture in the macro so that you are sure of their order and any prerequisites. For example, if you are searching for a particular character in a text string, does that character always appear in the same place? If not, how does that affect how you navigate to or select text you want to work with? Will it make your macro more efficient if you move to the start of the line or the start of the next paragraph when the macro’s work is complete? If you expect to use this macro in other documents, apply the steps again in a different context in another part of the document and see whether you observe any variations you should account for. For macros that involve more than a few steps, you might want to list the steps for reference.

You should also refresh your knowledge of how to select text and navigate a document with the keyboard. You cannot use the mouse to select text or reposition the cursor when you record a macro. You can, however, use the mouse to issue commands on the ribbon or to select options in a dialog box.

Note

See Also Refer to the Help topic “Keyboard Shortcuts for Microsoft Word” for information about navigating a document with the keyboard.

In the Record Macro dialog box, you specify several properties for a macro prior to recording it:

image with no caption
  • In the Macro Name text box, be sure to use a meaningful name even for simple macros (not just the default Macro1 or Macro2 that Word provides). Use a name that succinctly states the purpose of the macro, something like InsertTableforRFPs, AddMyHeader, or CheckForEMSpaces.

  • Specify where to store the macro by choosing an entry in the Store Macro In list. Use the setting All Documents (Normal.dotm) to add this macro to the Normal template, which makes the macro available in any document you create in Word. You can also store the macro in the current template (if the document is attached to a template other than Normal.dotm) or in the current document.

  • Use the Description box to add more details about what the macro does and when to run it.

Important

If you choose to save the macro in the current template or in the current document, the file you choose must be saved using the macro-enabled file format (.dotm for templates or .docm for documents).

The Record Macro dialog box lets you assign the macro to a custom keyboard shortcut or to a button you can add to the Quick Access Toolbar. You do not have to make such an assignment, but doing so makes the macro more accessible if you plan to use it repeatedly.

Note

See Also For information about assigning a macro to a button, see Adding a Custom Macro Button to the Quick Access Toolbar later in this chapter.

If you choose to assign a macro to the keyboard, Word opens the Customize Keyboard dialog box. The Save Changes In list specifies where to store the keyboard shortcut. In most cases, you should choose the setting here that matches your choice in the Record Macro dialog box. In other words, if you are saving the macro in Normal.dotm, also save the keyboard shortcut in Normal.dotm.

You use the Press New Shortcut Key box to enter the sequence of keys you want to use. You need to press the Ctrl key or the Alt key plus the key you want to use. You can add the Shift key to the Ctrl or Alt key combination for a larger number of choices. Word displays the text “Currently assigned to:” when you enter a key combination. You might need to experiment with different combinations to find one that is not assigned to another function (Word assigns certain functions to keystrokes by default—Ctrl+B and Ctrl+I for formatting, for example), or you can override the current assignment with your own. Be sure to click Assign in the Customize Keyboard dialog box before you click Close.

image with no caption

When you click OK in the Record Macro dialog box (or click Close in the Customize Keyboard dialog box), you are recording. The cursor looks like a cassette tape to confirm this. Follow the steps you want to save in this macro. You can pause and resume recording if you need to. When you finish the steps, click Stop Recording in the Code group.

image with no caption

Tip

You can also start and stop recording a macro by using buttons on the status bar. Right-click the status bar, and then make sure Macro Recording is selected to add this capability.

  • To record a macro

    1. In the Code group on the Developer tab, click Record Macro.

    2. In the Record Macro dialog box, type a name and description for the macro.

    3. In the Store macro in list, select the template or document in which you want to save the macro.

    4. Click OK, and then follow the steps you want to record in the macro.

    5. If necessary, in the Code group, click Pause Recording, and then click Resume Recording when you are ready to record again.

    6. In the Code group, click Stop Recording.

  • To assign a macro to the keyboard

    1. In the Record Macro dialog box, click Keyboard.

    2. In the Customize Keyboard dialog box, click in the Press new shortcut key box, press Alt or Ctrl (or both), and then press the key you want to assign the macro to.

    3. In the Save changes in list, select the template or document in which you want to save this keyboard shortcut.

    4. Click Assign, and then click Close.

Running a Macro

You can run a macro in several different ways:

  • Use the Run button in the Macros dialog box.

  • Assign the macro to the keyboard.

  • Assign the macro to a command button.

  • Assign the macro to a button that you can add to the Quick Access Toolbar.

Note

See Also For detailed information about the third and fourth options in this list, see Running a Macro from a Command Button and Adding a Custom Macro Button to the Quick Access Toolbar later in this chapter.

If you expect to run a macro only infrequently, using the Run button in the Macros dialog box is a simple approach. Click Macros in the Code group to open this dialog box, which lists each macro contained in the active templates and document. Click the macro you want to run, and then click Run.

image with no caption

If you assigned the macro to the keyboard when you recorded the macro, position the cursor where you want to start running the macro, and then press the key combination you assigned.

Note

See Also To learn how to assign a macro to the keyboard, see Using the Macro Recorder earlier in this chapter.

  • To run a macro from the Macros dialog box

    1. Position your cursor where you want to start running the macro.

    2. In the Code group, click Macros.

    3. In the Macros dialog box, select the macro you want to run and then click Run.

Applying Macro Security

Word provides four basic options related to macro security. You set these options in the Trust Center, which you can open by clicking Macro Security in the Code group.

image with no caption

These settings control the level of macro security in documents that you receive in e-mail, for example, or that you might download from the Internet. As the text that accompanies the last of these options indicates, enabling all macros is not recommended because macros might contain code written with malicious intent. You might use this option on a computer that only you have access to—one dedicated for testing, for example, or that you use under circumstances that you control to a high degree.

The third option, Disable All Macros Except Digitally Signed Macros, lets you work with macros that are provided by trusted publishers. If a document contains a macro that is not from a trusted publisher, Word displays a security warning that lets you enable the macros.

Note

See Also For more information about security settings in Word 2010, including trusted publishers, see Trust Center in Chapter 1 in this part of the book.

If you keep the default choice, Disable All Macros With Notification, you need to enable content before you can run a macro. Word displays a security warning in the Message bar indicating that macros (or active content) have been disabled. If you know that the macros come from a source you trust, click Enable Content to gain access to the macros. When you enable macros, the document becomes a trusted document.

image with no caption

Important

Word designates the default template location (UsersUsernameAppDataRoamingMicrosoftTemplates) as a trusted location. If you base documents on templates stored in this location, those documents are also trusted, and their active content is enabled when you open the document.

In documents that contain macros, you can also enable the macros by switching to Backstage view and clicking Enable Content in the Security Warning area of the Info tab. This approach provides some additional options. Choose the option Enable All Content to always enable the document’s active content, which makes the document a trusted document. If you choose Enable Content, Advanced Options, Word displays a Security Options dialog box. Select the option Enable Content For This Session to activate macros while you have the document open. The next time you open the document, you will need to enable content again.

image with no caption

5.2 Apply and Manipulate Macro Options

Word provides a number of options for how to run a macro, including built-in macros you can use if you want to run a macro when you open or close a document. In the following sections, you’ll learn how to use the AutoOpen macro, how to assign a macro to a command button, and how you can add a button that runs a macro to the Quick Access Toolbar.

Running a Macro When You Open a Document

You can define a macro that runs automatically when you open a document or when you create a document that’s based on a template. To do this, you need to name the macro AutoOpen (in the first case) or AutoNew, and you must save the macro in a macro-enabled document, using the .docm (for documents) or .dotm (for templates) file name extension.

For example, you might want to display a document in a particular view and at a certain zoom percentage each time you open it. In the Record Macro dialog box, name the macro AutoOpen, and then switch to the view and zoom settings you want to use as you record the macro.

You can test your macro by making a small edit to the document (for example, type your name or something similar). Now switch to a different view, change the zoom setting, and then save and close the document. Open it again, and you’ll see that the document is restored to the settings you specified in the macro.

In addition to AutoOpen, you can use the following Auto macros in Word:

  • AutoExec This macro runs when you start Word, before Word opens any document. You should save the AutoExec macro in the default template (Normal.dotm).

  • AutoNew The AutoNew macro runs when you create a new document based on the template in which the macro is defined. You might use the AutoNew macro to update fields in the document or to add information such as the document’s creation date to the header or footer.

  • AutoClose The AutoClose macro runs when you close a document. This macro should be saved in the current template.

  • AutoExit The AutoExit macro runs when you quit Word. Save the AutoExit macro in the default Normal.dotm template.

  • To run a macro when a document opens

    1. Open the document in which you want to define the macro.

    2. In the Code group on the Developer tab, click Record Macro.

    3. In the Record Macro dialog box, name the macro AutoOpen.

    4. Click OK, and follow the steps you want to record for the macro.

    5. Click Stop Recording when you finish, and then save and close the document.

    6. Open the document to test the macro you recorded.

Running a Macro from a Command Button

In the section 5.3 Create Forms later in this chapter, you will learn about the types of form controls you can use in Word 2010. One of the controls you can add to a document is a command button (a type of ActiveX control), which is included in the group of legacy controls you can find in the Controls group on the Developer tab. You can assign a macro to a command button that runs when you click the button.

For the most part, ActiveX controls need to be programmed to carry out their function. However, if you want to assign a macro to a command button and are unfamiliar with VBA, record the macro first. You can then refer to the macro by its name when you set up the command button.

Note

See Also For information about creating a macro, see Using the Macro Recorder earlier in this chapter.

To display the legacy tools in the Controls group, click the icon in the bottom-right corner. Click the command button icon, and Word adds a button to the document. Right-click the button, and then click View Code, which opens the Visual Basic editor with a click event procedure set up for the button.

image with no caption

To associate a macro with the command button, type the macro’s name between Private Sub CommandButton1_Click() and End Sub. Use this approach if you want to assign a macro you recorded to the command button. Notice in the previous screen shot that the names of two macros appear (UpdateSalesNumber and PrintReport). A command button is a convenient way to run more than one macro with a single click. When you set up the command button, type the name of each macro you want to run in the order you want to run them.

You can also copy code from a macro you recorded (or wrote) and paste the code between these lines. Of course, you can write the macro code yourself if you know enough about VBA.

  • To assign a macro to a command button

    1. On the Developer tab, in the Controls group, open the menu of legacy commands and then click the icon for the command button.

    2. Right-click the command button, and then click View Code.

    3. In the Visual Basic editor, type the name of a macro or add the code you want to run when you click the button.

    4. Close the Visual Basic editor. On the Developer tab, in the Controls group, click Design Mode to disable it, and then test the button.

Adding a Custom Macro Button to the Quick Access Toolbar

One of the most convenient ways to run a macro is to add a button for that macro to the Quick Access Toolbar. You can assign the macro to a button when you first record it (see Using the Macro Recorder earlier in this chapter) or customize the Quick Access Toolbar later by using the Word Options dialog box.

image with no caption

On the Customize The Quick Access Toolbar page, open the Choose Commands From list and select Macros. In the list of macros, select the one you want to add to the Quick Access Toolbar and then click Add. In the Customize Quick Access Toolbar list, select For All Documents if you want the button to appear on the Quick Access Toolbar for all documents you work on. You can also select the current document if you want to use the macro within that scope.

To rename the button or to change the icon associated with it, select it in the list of commands on the Quick Access Toolbar and then click Modify. Use the Modify Button dialog box to change the display name and to choose an icon. The display name appears in a ScreenTip when you point to the button with the mouse.

image with no caption
  • To add a custom macro button to the Quick Access Toolbar

    1. Click the arrow at the right end of the Quick Access Toolbar, and then click More Commands.

    2. In the Choose commands from list, choose Macros.

    3. In the list of macros, select the macro you want to place on the Quick Access Toolbar, and then click Add.

    4. Click Modify, and then select the icon you want to use and change the display name for the button.

5.3 Create Forms

Forms are more structured than many documents you create in Word. Forms are designed to collect specific information in particular formats and are often submitted to other people for processing or approval. Expense reports, invoices, order forms, and registration forms are among the types of forms you might create in Word.

Designing a Form

Although you can create a form for a single document, most forms are saved as a Word template so that they can be used more than once. Start with a blank template for a form you plan to design from scratch, or use one of the form templates available from Office.com as a starting point.

Note

See Also For more information about document templates, see 1.3 Apply a Template to a Document in Chapter 1 in this section of the book.

To keep content controls aligned in a form, you can use a table, although this is not a requirement. Click Design Mode in the Controls group on the Developer tab before you start adding controls to your form. Design mode lets you see the tags that identify the content controls and lets you arrange and edit the content controls you add to the form.

Here’s a quick rundown on the controls you can add to a form. Word displays a ScreenTip that identifies each control:

  • Rich text Use this control for text fields in which you need to format text as bold or italic, for example, or if you need to include multiple paragraphs and add other content such as images and tables.

  • Plain text Use the plain text control for simple text fields such as names, addresses, or job titles. The text added to a plain text control can be formatted only in limited ways.

  • Combo box In a combo box, users can select from a list of defined choices or type their own information. If you select the Contents Cannot Be Edited check box in the properties for this control, users won’t be able to add their own items to the list.

    Note

    See Also For more information about the Contents Cannot Be Edited option, see Locking Controls later in this chapter.

  • Drop-down list In this control, users can select only from a list of defined options. A drop-down list might be used to display department names or meeting rooms (a list of specific items), whereas a combo box would be better suited for displaying a list of tasks, for example, so that users can select a task if it appears on the list or define one if it doesn’t.

  • Building block Use a building block control when you want users of the form to choose a specific block of text or a building block from another of the galleries in Word. In a proposal, for example, you might include a building block control that lets users choose text entries from the Quick Parts gallery to indicate the length of time for which the proposal is valid.

  • Picture Use this control to embed an image file in a document. You could use a picture control to display a logo, for example, or pictures of project personnel.

  • Date picker This control inserts a calendar control that lets you select or enter a date.

  • Check box Use the check box control to provide a set of options—product sizes, for example, or options that indicate which events a user plans to attend.

You can add legacy controls available through the Controls group to your form if you are designing a form that will be used on computers on which earlier versions of Word are installed. The legacy controls available include those for a text box, a check box, and a drop-down list.

Note

See Also For more information about working with these controls, see Adding and Removing Form Fields later in this chapter.

You can also add one of many ActiveX controls to a form. For example, you can add a command button to a form and then assign a macro to the command button. To take full advantage of ActiveX controls on a form, you should know how to program the controls with VBA.

Note

See Also For more information, see Running a Macro from a Command Button earlier in this chapter.

Here’s an example of a conference registration form that’s being designed. The form uses (among other controls) plain text controls to gather personal information (name, address, city, and the like), date-picker controls for the arrival and departure dates, a combo box to list dietary preferences, a rich text control for the special requests area, and check boxes that users select to show which events they plan to attend.

image with no caption

Tip

To group content controls, select the controls and then click Group in the Controls group. For example, if you want to keep the check boxes together as a unit so that they cannot be edited or deleted individually, select those controls and then click Group.

  • To add a text content control

    1. Click where you want to insert the control.

    2. In the Controls group on the Developer tab, click Rich Text Content Control or Plain Text Content Control.

  • Insert a picture control

    1. Click where you want to insert the control.

    2. In the Controls group on the Developer tab, click Picture Content Control.

  • Insert a combo box or a drop-down list

    1. Click where you want to insert the control.

    2. In the Controls group on the Developer tab, click Combo Box Content Control or Drop-Down List Content Control.

    3. Select the content control, and then click Properties in the Controls group.

    4. In the Drop-Down List Properties area, click Add, and then use the Add Choice dialog box to define the first item for the list. Repeat this step to define each item required in the list.

    5. Select options for other properties, and then click OK.

  • Insert a date picker

    1. Click where you want to insert the date picker control.

    2. In the Controls group on the Developer tab, click Date Picker Content Control.

  • Insert a check box

    1. Click where you want to insert the check box control.

    2. In the Controls group on the Developer tab, click Check Box Content Control.

  • Insert a building block

    1. Click where you want to insert the control.

    2. In the Controls group on the Developer tab, click Building Block Gallery Content Control.

    3. Click the content control to select it, and then click Properties in the Controls group.

    4. Click the gallery and the category for the building blocks that you want to make available in the building block control, and then click OK.

  • To customize the text in a content control

    1. In the Controls group, click Design Mode.

    2. Select the content control you want to edit.

    3. Edit the placeholder text, and apply any formatting.

    4. In the Controls group, click Design Mode again.

Working with Control Properties

Each control you add to a form has a set of properties. The most basic properties are Title and Tag. You can also choose how to format the contents of a control and set options for whether the control can be deleted and whether its content can be edited. Other properties depend on the type of control you are working with. For example, for a plain text control, you can set an option to allow multiple paragraphs. (If you keep the check box for this option clear, users can enter only a single paragraph in the control.) The date-picker control has a fairly extensive set of properties, including the date format, the locale, and the calendar type.

image with no caption

A title appears on the control to better identify it. The tag you define helps you locate a control and is involved if you link your form to a data source. Tags appear on either end of a control when you work in Design mode.

To open the Content Control Properties dialog box for a control, select the control and then click Properties in the Controls group.

The following sections provide more information on specific control properties.

Locking Controls

Two options you can apply to controls help you protect the design and content of your form. The first option (Content Control Cannot Be Deleted) prevents a user of a form from deleting that control. You should set this property on every control that is required in the form, but you should not set this property for controls that are optional. For example, you might design a form in which users need to select one of two text controls to display standardized text given specific conditions. The users need to delete the text control that doesn’t apply. (Although a better approach in this case might be to include a building block content control and let users select the applicable text from the Quick Parts gallery.)

You can also set a property that prevents users from editing the content of a control. This option is suitable for titles, for example, or other controls whose content should remain static, such as text controls that display standardized text. But many controls require users to type text, choose an option, or select from a list. For controls of that nature, you should not set the option to prevent the content of a control from being edited.

Note

See Also For more information about restricting the editing of a form, see Locking and Unlocking a Form later in this chapter.

Formatting a Control

In the Content Control Properties dialog box, select the check box labeled Use A Style To Format Contents when you want to apply a style to the content in a control. You can choose a style from the Style list, or click New Style and use the Create New Style From Formatting dialog box to specify formatting attributes for the font and define other elements for the style.

Note

See Also For more information about creating styles, see 2.1 Apply Advanced Font and Paragraph Attributes in Chapter 2 in this section of the book.

Building a List

If you are using a combo box or list box content control, the Content Control Properties dialog box includes fields that you use to define list items. In the dialog box, click Add to begin, and then specify the display name and value for the first list item in the Add Choice dialog box. By default, Word enters what you type in the Display Name box in the Value box (or vice versa, if you type a value first). You can change the value to be different (a numerical value to match the sequence of choices, for example). After you build the list, use the Modify, Remove, Move Up, and Move Down buttons to refine the list as you need to.

image with no caption
  • To lock a control

    1. Select the content control, and then click Properties in the Controls group.

    2. In the Content Control Properties dialog box, in the Locking area, select one or both of the options that apply:

      • Content Control Cannot Be Deleted

      • Contents Cannot Be Edited

    3. Click OK.

  • To format a control

    1. Select the content control, and then click Properties in the Controls group.

    2. In the Content Controls Properties dialog box, select the Use a style to format contents check box.

    3. Choose a style from the Style list, or click New Style and then define the attributes of the style in the Create New Style From Formatting dialog box.

    4. Click OK in the Create New Style From Formatting dialog box, and then click OK in the Content Controls Properties dialog box.

  • To define a list

    1. Select the content control, and then click Properties in the Controls group.

    2. In the Drop-Down List Properties area, click Add, and then use the Add Choice dialog box to define the first item for the list. Repeat this step to define each item required in the list.

    3. Select options for other properties, and then click OK.

Adding Help to a Form

Content controls include a simple text statement that tells users what to do with the control. For example, text controls indicate “Click here to enter text,” and the date-picker control prompts users with “Click here to enter a date.” You can change this text so that it provides precise instructions and helps users work with a form more efficiently. Adding directions like this can also simplify a form. For example, with the addition of an introductory sentence, the contact information required in the reservation form under development can be reduced to a single column.

image with no caption

Changing the text is a simple operation. Click Design Mode in the Controls group on the Developer tab. Select the control whose text you want to change, select the text it contains, and then type the new text.

  • To customize the text in a content control

    1. In the Controls group, click Design Mode.

    2. Select the content control you want to edit.

    3. Edit the placeholder text, and apply any formatting.

    4. In the Controls group, click Design Mode again.

Assigning XML Elements to Form Controls

An XML schema describes the structure of an XML document. A schema can, for example, define the elements required in an XML document, an element’s attributes, and the default values for elements and attributes. When you associate an XML schema with a Word document that contains content controls, you can create a relationship between the control and an XML element defined in the schema. The relationships you create can serve as the basis for linking the form to a database. For example, users could enter data in a Word form that is attached to an XML schema, and then that data could be imported into a database table that is based on the same schema or on a compatible one.

Note

See Also If you want to learn more about XML and XML schemas, you can find additional information plus a number of tutorials at www.w3schools.com/xml/default.asp.

To set up this process, you first need to attach a schema to your form in Word. You can do this by clicking Schema in the XML group on the Developer tab. In the Templates And Add-Ins dialog box, click Add Schema, and then select the schema you want to apply. In the Schema Settings dialog box, you can add an alias for the schema if you want to. By assigning an alias, you can shorten the text string required to refer to the schema.

When you click OK in the Templates And Add-Ins dialog box, Word displays the XML Structure task pane. Before you assign specific elements to a content control, you need to add the root element to the document and any parent elements defined in the schema. To add the root element, select the entire document and then select the root element in the area at the bottom of the XML Structure task pane.

image with no caption

To associate an element with a content control, right-click the control, point to Apply XML Element on the menu that appears, and then choose the element you want to use. (Or you can select the control and then select the element you want to associate with it in the XML Structure task pane.)

Tip

The tags you define for a content control (and that Word displays when you click Design Mode) do not provide links to the XML, even if they match the name of an element, but entering a tag name for the control can help you understand the structure of the XML you are applying.

  • To assign an XML element to a content control

    1. On the Developer tab, click Schema in the XML group.

    2. In the Templates and Add-Ins dialog box, click Add Schema.

    3. In the Add Schema dialog box, select the schema and then click Open.

    4. Click OK in the Templates and Add-Ins dialog box.

    5. Select the entire document. At the bottom of the XML Structure pane, select the schema’s root element in the Choose an element to apply to your current selection list.

    6. Use the XML element list to add any parent elements.

    7. Right-click the content control you want to assign an XML element to, point to Apply XML Element, and then select the element.

5.4 Manipulate Forms

In this section, you will learn about other steps you can take to protect a form from unexpected and unwanted changes. You will also learn how to add and remove form fields you want to use on a form.

Locking and Unlocking a Form

As you can with other types of documents, you can restrict the types of changes users can make to a form. After you have designed a form and set properties for the controls it contains, use the Restrict Editing command on the Developer tab to display the Restrict Formatting And Editing pane.

Choose the option to limit formatting if you want to maintain the look and feel of the form. Select the Editing Restrictions check box, and then choose Filling In Forms from the list. This option sets up the form so that users can edit controls as you designated, but users cannot change the design of the form or alter the text in titles or other labels.

image with no caption

Note

See Also The option Filling In Forms does not let you specify groups or individuals who can make changes to the document. It just controls how users can work with the form. For more information on restricting editing to groups or individuals, see 1.2 Apply Protection to a Document in Chapter 1 in this section of the book.

Click Yes, Start Enforcing Protection to apply your restrictions. You then need to define a password to protect the document.

Tip

To specify users who can bypass editing restrictions and work with the form while protection is applied, click Restrict Permission at the bottom of the Restrict Formatting And Editing task pane. In the Select User dialog box, select the user accounts to which you want to grant this privilege.

When a user bases a new document on the form template you’ve designed, he or she can fill in the required fields but cannot perform other types of edits. If a user clicks Restrict Editing, the task pane that Word displays describes this situation and presents the user with a Stop Protection button. To unlock the form and do work other than fill in its fields, a user must click Stop Protection and then type the password defined earlier.

  • To lock a form

    1. On the Developer tab, in the Protect group, click Restrict Editing.

    2. In the Restrict Formatting and Editing task pane, select Allow only this type of editing in the document in the Editing Restrictions area, and then choose Filling in Forms from the list.

    3. Click Yes, Start Enforcing Protection.

    4. In the Start Enforcing Protection dialog box, type a password and then type the password again to confirm it.

    5. Click OK in the Start Enforcing Protection dialog box.

Adding and Removing Form Fields

As mentioned earlier in the section Designing a Form, you can use legacy form fields in addition to the Word 2010 content controls. You can add these fields from the Controls group or by adding the Form Field button to a custom group you create on the ribbon.

Note

See Also For detailed information about customizing the ribbon, see Modifying the Display of the Ribbon at the beginning of this book.

In the Form Field dialog box, which Word displays when you click the Form Field button, you first select the type of form field you want to add to the form in Word. The choices are Text, Check Box, and Drop-Down. After you make your choice, click Options.

image with no caption

Here is a summary of the options you can set for each type of form field:

  • Text In the Type list, you can choose the type of data the text field will contain (including Regular Text, Number, and Date). The Type list also includes Calculation, which lets you define an expression that is evaluated when a user works with the form field.

    Use the Default Text box to define the text (or number or date) you want the field to show by default. In the Maximum Length box, Unlimited is the default option, but you can specify a certain number of characters. For example, a product ID might include exactly nine characters, and you can specify that under Maximum Length. The Text Format list changes depending on the choice you make in the Type list. Currency formatting options, for example, are available when you select Number in the Type list.

    Use the Run Macro On lists to select a macro that you want Word to run when a user enters or exits the field. Leave the Fill-In Enabled check box selected if you want users to be able to edit the contents of the field. Select Calculate On Exit if the form field is set up to calculate an expression.

  • Check box For a check box form field, you can specify its size and whether it is selected or not selected by default. As you can with a text form field, you can specify a macro that runs when a user enters or exits the field.

  • Drop-down Use the Options dialog box for a drop-down form field to define the items for the list. Type each item in the Drop-Down Item box, and then click Add. In the Run Macro On lists, choose a macro if you want to run one when a user enters or exits this field.

The Options dialog box for each type of form field includes the Add Help Text button. The Form Field Help Text dialog box contains two tabs: Status Bar and Help Key (F1). You can select AutoText entry and then choose an item from the list provided by Word, or select Type Your Own and then type the help text you want users to see on the status bar or in the Help window when a user presses F1.

image with no caption

Form fields do not become active unless you follow the steps outlined in the previous section (Locking and Unlocking a Form) to apply editing restrictions for the form. When editing restrictions are enforced, you cannot change the properties of a form field. You must stop protection (by entering the specified password) before you can make any adjustments.

To remove a form field, remove protection from the form if necessary, select the field, and then press Delete.

  • To add a form field to a form

    1. Add the Form Field button to a custom group on the ribbon.

    2. Click Form Field, and then select the type of form field you want to add (text, check box, or drop-down).

    3. In the Form Field dialog box, click Options.

    4. In the Form Field options dialog box, set properties for the form field (for example, define the list items for a drop-down field form, or specify the default value for a text form field).

    5. Click Add Help Text, and then define the help text you want to appear on the status bar and in the Help window.

    6. After you finish adding form fields and defining each field’s properties, click Restrict Editing on the Developer tab.

    7. In the Formatting and Editing Restrictions pane, select the check box under Editing Restrictions, and then select Filling in forms from the list.

    8. Click Yes, Start Enforcing Protection, and then type the password you want to use to protect this form.

  • To remove a form field

    1. With the form open, click Restrict Editing on the Developer tab.

    2. In the Restrict Formatting and Editing pane, click Stop Protection.

    3. Type the password used to protect the form, and then click OK.

    4. Select the form field you want to remove, and then press Delete.

Objective Review

Before finishing this chapter, be sure that you have mastered the following skills:

5.1 Apply and Manipulate Macros
5.2 Apply and Manipulate Macro Options
5.3 Create Forms
5.4 Manipulate Forms
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.180.111