17. Expanding Word Functionality

Introduction

An add-in extends the functionality of Word and other Microsoft Office programs. Word includes a variety of addins—programs that are included with Word but not essential to its functionality. Before you can use a Word or a third-party add-in, you need to load it first. When you load an add-in, the feature may add a command to a Ribbon tab.

If you want to customize Microsoft Word and create advanced documents, you’ll need to learn how to work with the Microsoft Office programming language, Microsoft Visual Basic for Applications (VBA). VBA is powerful and flexible, and you can use it in all major Office applications. To create a VBA application, you have to learn VBA conventions and syntax. Office makes VBA more user-friendly by providing the Visual Basic Editor, an application that includes several tools to help you write error-free VBA applications. The Visual Basic Editor provides extensive online Help to assist you in this task.

A practical way to use VBA is to create macros. Macros can simplify common repetitive tasks that you regularly use in Word. Macros can reside on the Quick Access Toolbar for easy access. If a macro has a problem executing a task, the Visual Basic Editor can help you debug, or fix the error in your macro.

An ActiveX control is a software component that adds functionality to an existing program. An ActiveX control supports a customizable, programmatic interface for you to create your own functionality, such as a form. Word includes several pre-built ActiveX controls—including a label, text box, command button, and check box—to help you create a user interface.

Viewing and Managing Add-ins

An add-in extends functionality to Word and other Microsoft Office programs. An add-in can add buttons and custom commands to the Ribbon or menu items on the File tab (New!). You can get add-ins for Word on the Office.com Web site in the Downloads area, or on third-party vendor Web sites. When you download and install an add-in, it appears on the Add-Ins or other tabs depending on functionality, and includes a special ScreenTip that identifies the developer. You can view and manage add-ins from the Add-Ins pane in Word Options.

View Installed Add-ins

Image Click the Add-Ins tab, or click the File tab, click Add-Ins, point to an add-in menu option, and then select a command (New!).

Add-ins with buttons and controls appear on the Ribbon. To display a ScreenTip, point to a button or control.

Image Click the File tab, and then click Options.

Image In the left pane, click Add-Ins.

The installed add-ins appear in the list by category.

Image Active Application Add-ins. Lists the registered and running add-ins. A selected check box for a COM add-in appears here.

Image Inactive Application Add-ins. Lists the installed add-ins, but not currently loaded. A cleared check box for a COM add-in appears here.

Image Document Related Add-ins. Lists template files currently open in a document.

Image Disabled Application Add-ins. Lists automatically disabled add-ins causing Office programs to crash.

Image Click an add-in to display information about it.

Image Click OK.

Image

Image

Image

Image

Manage Installed Add-ins

Image Click the File tab, and then click Options.

Image In the left pane, click Add-Ins.

Image Click the Manage list arrow, and then click the add-in list you want to display:

Image COM Add-ins. Opens the COM Add-Ins dialog box and lists the Component Object Model (COM) add-ins.

Image Actions. Opens the AutoCorrect dialog with the Actions tab and list the installed actions (New!).

Image Word Add-ins. Opens the Templates and Add-ins dialog box with the Templates tab and lists the currently installed Word add-ins.

Image Templates. Opens the Templates and Add-ins dialog box with the Templates tab and lists the currently installed global templates.

Image XML Schemas. Opens the Templates and Add-ins dialog box with the XML Schema tab.

Image XML Expansion Pack. Opens the Templates and Add-ins dialog box with the XML Expansion Packs tab. XML Expansion Packs provide additional XML functionality.

Image Disabled Items. Opens the Disabled Items dialog box and lists the disabled items that prevent Word from working properly. If you want to try and enable an item, select it, click Enable, click Close, and then restart Word.

Image Click Go.

Image Click OK.

Image

Image

Image

Loading and Unloading Add-ins

Add-ins are additional programs, designed to run seamlessly within Word or Office. There are two main types of add-ins: Word and Component Object Model (COM). Word add-ins are custom controls designed specifically for Word, while COM add-ins are designed to run in one or more Office programs and use the file name extension .dll or .exe. Some add-ins are installed when you run the Setup program, while others can be downloaded from Office.com or purchased from third-party vendors. To load or unload add-ins, Word provides commands you can access from an added button on the Quick Access Toolbar, Developer tab, or the Add-Ins pane in Word Options. When you load an add-in, the feature may add a command to a tab or toolbar. You can load one or more add-ins. If you no longer need an add-in, you should unload it to save memory and reduce the number of commands on a tab. When you unload an add-in, you also may need to restart Word to remove an add-in command from a tab.

Load or Unload a Word Add-in

Image Click the Developer tab.

Image To display the Developer tab, use the Customize Ribbon pane in Options.

Image Click the Add-Ins or Document Template button.

Image Select or clear the check box next to the global template or add-in you want to load or unload.

Image To add or remove a global template or add-in, do one of the following:

Image Add. Click Add, navigate to the folder that contains the add-in, click the Files of type list arrow, select Word Add-Ins, click the add-in, and then click OK.

Image Remove. Select the item you want to remove, and then click Remove.

Image Click OK.

Image

Load or Unload a COM Add-in

Image Click the Developer tab.

Image To display the Developer tab, use the Customize Ribbon pane in Options.

Image Click the COM Add-Ins button.

Image Select the check box next to the add-in you want to load, or clear the check box you want to unload.

TROUBLE? If the add-in is not available in the list, click Add, locate and select the add-in you want, and then click OK.

Image To remove the selected add-in, click Remove.

Image Click OK.

Did You Know?

You can can get more information about COM online. Visit www.microsoft.com/com.

You can open an add-in dialog box from Word Options. Click the File tab, click Options, click Add-ins, click the Manage list arrow, click Word Add-ins or COM Add-ins, and then click Go.

See Also

See “Working with Toolbars” on page 6 for information on adding a button to the Quick Access Toolbar.

See “Setting Developer Options” on page 409 for information on displaying the Developer tab.

Image

For Your Information

Dealing with an Add-in Security Alert

When there is a problem with an add-in, Word disables it to protect the program and your data. When a problem does occur, a security alert dialog box appears, displaying information about the problem and options you can choose to fix or ignore it. You can choose an option to help protect you from unknown content (recommended), enable this add-in for this session only, or enable all code published by this publisher. See “Setting Add-in Security Options” on page 332 for more information about setting options that trigger the Add-in security alert.

Enhancing a Document with VBA

Office applications like Word, Access, Excel, PowerPoint, and Visio share a common programming language: Visual Basic for Applications (VBA). With VBA, you can develop applications that combine tools from these Office products, as well as other programs that support VBA. Because of the language’s power and flexibility, programmers often prefer to use VBA to customize their Office applications.

Introducing the Structure of VBA

VBA is an object-oriented programming language because, when you develop a VBA application, you manipulate objects. An object can be anything within your document, such as a shape, text box, picture, or table. Even Word itself is considered an object. Objects can have properties that describe the object’s characteristics. Text boxes, for example, have the Font property, which describes the font Word uses to display the text. A text box also has properties that indicate whether the text is bold or italic.

Objects also have methods—actions that can be done to the object. Deleting and inserting are examples of methods available with a record object. Closely related to methods are events. An event is a specific action that occurs on or with an object. Clicking a button initiates the Click event for the button object. VBA also refers to an event associated with an object as an event property. The form button, for example, has the Click event property. You can use VBA to either respond to an event or to initiate an event.

Writing VBA Code

A VBA programmer types the statements, or code, that make up the VBA program. Those statements follow a set of rules, called syntax, that govern how commands are formulated. For example, to change the property of a particular object, the command follows the general form:

Object. Property = Expression

Where Object is the name of a VBA object, Property is the name of a property that object has, and Expression is a value that will be assigned to the property. The following statement turns on track changes in the active document:

ActiveDocument. TrackRevisions = TRUE

You can use Office and VBA’s online Help to learn about specific object and property names. If you want to apply a method to an object, the syntax is:

Object. Method arg1, arg2, …

Where Object is the name of a VBA object, Method is the name of method that can be applied to that object, and arg1, arg2, … are optional arguments that provide additional information for the method operation. For example, to clear the Find and Replace formatting, you could use the following method:

Selection. Find. ClearFormatting

Selection. Find. Replacement. ClearFormatting

Working with Procedures

You don’t run VBA commands individually. Instead they are organized into groups of commands called procedures. A procedure either performs an action or calculates a value. Procedures that perform actions are called Sub procedures. You can run a Sub procedure directly, or Office can run it for you in response to an event, such as clicking a button or opening a form. A Sub procedure initiated by an event is also called an event procedure. Office provides event procedure templates to help you easily create procedures for common events. Event procedures are displayed in each object’s event properties list.

A procedure that calculates a value is called a function procedure. By creating function procedures you can create your own function library, supplementing the Office collection of built-in functions. You can access these functions from within the Expression Builder, making it easy for them to be used over and over again.

Working with Modules

Procedures are collected and organized within modules. Modules generally belong to two types: class modules and standard modules. A class module is associated with a specific object. In more advanced VBA programs, the class module can be associated with an object created by the user. Standard modules are not associated with specific objects, and they can be run from anywhere within a database. This is usually not the case with class modules. Standard modules are listed in the Database window on the Modules Object list.

Building VBA Projects

A collection of modules is further organized into a project. Usually a project has the same name as a document. You can create projects that are not tied into any specific document, saving them as Word add-ins that provide extra functionality to Word.

Using the Visual Basic Editor

You create VBA commands, procedures, and modules in Office’s Visual Basic Editor. This is the same editor used by Word and other Office programs. Thus, you can apply what you learn about creating programs in Word to these other applications.

The Project Explorer

One of the fundamental tools in the Visual Basic Editor is the Project Explorer. The Project Explorer presents a hierarchical view of all of the projects and modules currently open in Word, including standard and class modules.

The Modules Window

You write all of your VBA code in the Modules window. The Modules window acts as a basic text editor, but it includes several tools to help you write error-free codes. Word also provides hints as you write your code to help you avoid syntax errors.

The Object Browser

There are hundreds of objects available to you. Each object has a myriad of properties, methods, and events. Trying to keep track of all of them is daunting, but the Visual Basic Editor supplies the Object Browser, which helps you examine the complete collection of objects, properties, and methods available for a given object.

Viewing the Visual Basic Editor

Image

Setting Developer Options

The Developer tab is a specialized Ribbon that you can use to access developer controls, write code, or create macros. You can set an option in the Customize Ribbon pane in Word Options to show or hide the Developer tab. As a developer, you can also set an option to show errors in your user interface customization code.

Set Developer Options

Image Click the File tab, and then click Options.

Image In the left pane, click Customize Ribbon.

Image Select the Developer check box to display the Developer tab.

Image In the left pane, click Advanced.

Image Select the Show add-in user interface errors check box.

Image Click OK.

Image

Image

Understanding How Macros Automate Your Work

To complete many tasks in Word, you need to execute a series of commands and actions. To print two copies of a selected text in a document, for example, you need to open the document, select the text, open the Print dialog box, and specify that you want to print two copies. If you often need to complete the same task, you’ll find yourself repeatedly taking the same series of steps. It can be tiresome to continually repeat the same commands and actions when you can easily create a mini-program, or macro, that accomplishes all of them with a single command.

Creating a macro is easy and requires no programming knowledge on your part. Word simply records the steps you want included in the macro while you use the keyboard and mouse. When you record a macro, Word stores the list of commands with any name you choose. You can store your macros in the current document or in a new document.

Once a macro is created, you can make modifications to it, add comments so other users will understand its purpose, and test it to make sure it runs correctly.

You can run a macro by choosing the Macro command on the View or Developer tab, or by using a shortcut key or clicking a Quick Access Toolbar button you’ve assigned to it. From the Macro dialog box, you can run, edit, test, or delete any Word macro on your system, or create a new one.

If you have problems with a macro, you can step through the macro one command at a time, known as debugging. Once you identify any errors in the macro, you can edit it.

Image

Recording a Macro

If you find yourself repeating the same set of steps over and over, you can record a macro. Macros can run several tasks for you at the click of a button. When you turn on the macro recorder, Word records every mouse click and keystroke action you execute until you turn off the recorder. You can even record formatting changes to charts and other objects (New!). Then you can “play,” or run, the macro whenever you want to repeat that series of actions—but Word will execute them at a much faster rate. The macro recorder doesn’t record in real time, so you can take your time to correctly complete each action.

Record a Macro

Image Click the Developer or View tab.

Image Click the Record Macro button.

Image If you use the View tab, click View Macros on the menu.

TIMESAVER To quickly start or stop a macro recording, click the Record icon or Stop Record icon on the Status bar (left side).

Image Type a name for the macro.

Image Assign a shortcut key to use a keystroke combination or assign a button to run the macro.

Image Click the Store macro in list arrow, and then select a location.

Image All Documents. The macro is available whenever you use Word.

Image Documents Based On. The macro is available in documents based on this document.

Image This Document. The macro is available only in this document.

Image If you want, type a description.

Image Click OK.

Image Execute the commands or actions you want to complete the task.

Image Click the Stop Recording button.

Image

Image

Creating a Macro

If you find yourself repeating the same set of steps over and over, or if you need to add new functionality to Word, you could create a macro. If you find it difficult to record a macro, you can create one using a programming language called Microsoft Visual Basic for Applications (VBA). With VBA, you create a macro by writing a script to replay the actions you want. The macros for a particular document are stored in a macro module, which is a collection of Visual Basic codes.

Create a Macro

Image Click the Developer or View tab.

Image Click the Macros button.

Image If you use the View tab, click View Macros on the menu.

Image Type a name for the macro.

Image Click the Macros in list arrow, and then click All active templates and documents or the document to which you want the macro stored.

Image Click Create.

The Microsoft Visual Basic window opens.

Image Click the Module window (if necessary), and then type new Visual Basic commands, or edit existing ones.

To run the macro, press F5.

Image When you’re done, click the Save button, click the File menu, and then click Close and Return to Microsoft Word.

Image

Image

Running a Macro

Running a macro is similar to choosing a command in Word. When you record or edit the macro, you have the choice of making it available through a menu command, a keyboard combination, or even a toolbar button. As with other options in Word, your choice depends on your personal preferences—and you can choose to make more than one option available. Where you store a macro when you save it determines its availability later. Macros stored in the Personal Macro document are always available, and macros stored in any other documents are only available when the document is open.

Run a Macro

Image Click the Developer or View tab.

Image Click the Macros button.

Image If you use the View tab, click View Macros on the menu.

TIMESAVER Click the Macros button on the Status bar.

Image Click the macro you want to run.

Image Click Run.

Image

Delete a Macro

Image Click the Developer or View tab.

Image Click the Macros button.

Image If you use the View tab, click View Macros on the menu.

Image Click the macro you want to delete.

Image Click Delete, and then click Delete again to confirm the deletion.

Did You Know?

You can stop a macro. Press Ctrl+Break to stop a macro before it completes its actions.

Image

Controlling a Macro

If a macro doesn’t work exactly the way you want it to, you can fix the problem using Microsoft Visual Basic for Applications (VBA). VBA allows you to debug, or repair, an existing macro so that you change only the actions that aren’t working correctly. All macros for a particular document are stored in a macro module, a collection of Visual Basic programming codes that you can copy to other document files. You can view and edit your Visual Basic modules using the Visual Basic editor. By learning Visual Basic you can greatly increase the scope and power of your programs.

Debug a Macro Using Step Mode

Image Click the Developer or View tab.

Image Click the Macros button.

Image If you use the View tab, click View Macros on the menu.

Image Click the macro you want to debug.

Image Click Step Into.

The Microsoft Visual Basic window opens.

Image Click the Debug menu, and then click Step Into (or press F8) to proceed through each action.

Image You can also use other commands like Step Over and Step Out to debug the code.

Image When you’re done, click the Save button, click the File menu, and then click Close and Return to Microsoft Word.

Image Click OK to stop the debugger.

Did You Know?

You can display the Debug toolbar. In the Visual Basic editor, click the View menu, point to Toolbars, and then click Debug.

Image

Image

Edit a Macro

Image Click the Developer or View tab.

Image Click the Macros button.

Image If you use the View tab, click View Macros on the menu.

Image To open a macro, click the macro you want to change, and then click the View Code button.

Image Click the Module window containing the Visual Basic code for your macro.

Image Type new Visual Basic commands, or edit the commands already present.

Image Click the Save button, and then click the program Close button.

Image

Copy a Macro Module to Another Document

Image Open the document files you want to copy the macro from and to.

Image Click the Developer tab.

Image Click the Visual Basic button.

Image Click the View menu, and then click Project Explorer.

Image Drag the module you want to copy from the source document to the destination document.

Image Click the Save button, and then click the program Close button.

Image

Adding a Digital Signature to a Macro Project

If you want to add a digital signature to a document with a macro, you need to add it using the Visual Basic editor. If you open a document that contains a signed macro project with a problem, the macro is disabled by default and the Message Bar appears to notify you of the potential problem. You can click Options or Enable Content in the Message Bar to view or use it. For more details, you can click Show Signature Details to view certificate. If a digital signature has problems—it’s expired, not issued by a trusted publisher, or the document has been altered—the certificate information image contains a red X. When there’s a problem, contact the signer to have them fix it, or save the document to a trusted location, where you can run the macro without security checks.

Sign a Macro Project

Image Open the document that contains the macro project, and then click the Developer tab.

Image Click the Visual Basic button to open the Visual Basic window.

Image Click the Tools menu, and then click Digital Signature.

Image Click Choose.

Image Select a certificate in the list.

Image To view a certificate, click View Certificate or a link, and then click OK.

Image Click OK.

Image Click OK again.

Image Click the Save button, click the File menu, and then click Close and Return to Microsoft Word.

Did You Know?

You can create a self-signing certificate for a macro project. Click the Start button, point to All Programs, click Microsoft Office, click Microsoft Office Tools, click Digital Certificate For VBA Projects, enter a name, and then click OK. Office programs trust a self-signed certificate only on the computer that created it.

Image

Image

Image

Assigning a Macro to a Toolbar

After you create a macro, you can add the macro to the Quick Access Toolbar for easy access. When you create a macro, the macro name appears in the list of available commands when you customize the Quick Access Toolbar in Word Options. When you point to a macro button on the Quick Access Toolbar, a ScreenTip appears, displaying Macro: document name!macro name.

Assign a Macro to a Toolbar

Image Click the Customize Quick Access Toolbar list arrow, and then click More Commands.

Image You can also click the File tab, click Options, and then click Quick Access Toolbar.

Image Click the Choose command from list arrow, and then click Macros.

Image Click the Customize Quick Access Toolbar list arrow, and then click For all documents (default).

Image Click the macro you want to add (left column).

Image Click Add.

Image Click the Move Up and Move Down arrow buttons to arrange the commands in the order you want them to appear.

Image Click Modify.

Image Type a name for the button.

Image Click an icon in the symbol list.

Image Click OK.

Image Click OK.

See Also

See “Working with Toolbars” on page 6 and “Accessing Commands Not in the Ribbon” on page 396 for information on using the Quick Access Toolbar.

Image

Image

Image

Saving a Document with Macros

Macros are created using Visual Basic for Applications (VBA) code. If you add a macro to a document, you need to save it with a file name extension that ends with an “m”, either Word Macro-Enabled Document (.docm), or Word Macro-Enabled Template (.dotm). If you try to save a document containing a macro with a file name extension that ends with an “x” (such as .docx or .dotx), Word displays an alert message, restricting the operation. These Word file types are designated to be VBA code-free.

Save a Document with Macros

Image Click the File tab, and then click Save As.

Image Click the Save in list arrow, and then click the drive or folder where you want to save the file.

Image Type a document file name.

Image If necessary, click the Save as type list arrow, and then select the macro format you want:

Image Word Macro-EnabledDocument. A document (.docm) that contains VBA code.

Image Word Macro-Enabled Template. A template (.dotm) that includes preapproved macros.

Image Click Save.

Image

Opening a Document with Macros

When you open a document with a macro, VBA, or other software code, Word displays a security warning to let you know the document might contain potentially harmful code that may harm your computer. If you know and trust the author of the document, you can change security options to enable the macro content and use the document normally. If you don’t trust the content, you can continue to block and disable the content and use the document with limited functionality in Protected view (New!). If you don’t want a security alert to appear, you can change security settings in the Trust Center in Word Options.

Open a Document with Macros

Image Click the File tab, and then click Open.

Image If necessary, click the File as type list arrow, and then the document type that contains a macro.

Image If the file is located in another folder, click the Look in list arrow, and then navigate to the file.

Image Click the document with macros you want to open, and then click Open.

Image Click the File tab, click Info, click the Enable Content button (New!), and then click Advanced Options. To enable all content (make trusted), click Enable All Content on the menu.

Image You can also click Enable Content in the Message Bar with the Security Warning.

Image If you trust the document content, click the Enable content for this session option to use it. If you don’t trust it, click the Help protect me from unknown content (recommended) option to block and disable the macros.

Image Click OK.

Image

Image

Using Content Controls to Create Documents

Forms are an easy way for you to interact with users of your documents, either online or in print, and gain information and feedback from them in the process. Controls—either Content, Form, and ActiveX—are predefined fields or set of fields that contain information you can use throughout a document. Word includes many different types: text boxes for typed entries, date picker, combo boxes, drop-down lists, and check boxes. The fields display information you provided in Document Properties or a placeholder, which you can fill in. After you insert the fields you want, you can change field properties to customize the form. Word uses Content controls and Quick Parts as part of the program to build page covers, headers and footers, pull quotes, and side bar to name a few.

Add Controls to a Document

Image Click the Developer tab.

Image Position the insertion point where you want to insert a control.

Image Use the buttons in the Controls group to insert controls.

Image Rich Text or Text. Click to insert a text box where you can enter text.

Image Picture. Click to insert a placeholder where you can insert a picture.

Image Combo Box. Click to insert a combo box control.

Image Drop Down List. Click to insert a drop down list control where you can select from a list.

Image Date Picker. Click to insert a control to select a date from a pop-up calendar.

Image Building Block Gallery. Click to insert a Quick Part control where you can specify the information you want.

Image Legacy Tools. Click to select form and ActiveX controls.

Image Group. Select contents you want to protect; prevents changes to document.

Image

Image

Set or Change Control Properties

Image Click the Developer tab.

Image Select the control you want to set or change properties.

Image Click the Properties button.

Image Select the new options you want for the form field.

Image Click OK.

Did You Know?

You can prevent any changes to a document except content controls. Open the document with content controls, click the Developer tab, select the text you don’t want to get changed, click the Group button, and then click Group. You can not change any of the grouped text. However, you can enter text or specify options using the content controls. To remove the protection, click the Group button, and then click Ungroup.

You can protect a form or document. Click the Restrict Editing button on the Developer tab, and then Restrict Formatting and Editing to prevent users of the form from being able to edit its content (not their answers, but the questions and choices themselves).

Image

For Your Information

Mapping Content Controls to XML Data

You can map most content controls to elements in XML data attached to a document. XML data is stored in document parts using the Office XML file formats; for Word the XML file format is .docx. Document parts help define sections of the overall contents of the file. The file format consists of many different types of document parts, including custom XML data part. All document content associated with an XML element maps to data in a custom XML data part. This separation of the XML from the document formatting and layout—known as the Open Packaging Convention—makes it easier to access data. To view the document parts (which is a compressed zip package), add .zip to the end of the document name after the .docx, and then double-click the renamed file. The contents of the file appear, displaying a tree structure of individual document parts. You can move the custom.xml document part out of the zip file to open and modify it. You can attach the XML file to other Office documents to reuse data. When you’re done changing the XML file, you can move it back into the zip file and use it with the original file.

Inserting ActiveX Controls

An ActiveX control is a software component that adds functionality to an existing program. An ActiveX control is really just another term for an OLE (Object Linking and Embedding) object, known as a Component Object Model (COM) object. An ActiveX control supports a customizable, programmatic interface. Word includes several pre-built ActiveX controls on the Developer tab, including a label, text box, command button, image, scroll bar, check box, option button, combo box, list box, and toggle button. To create an ActiveX control, click the Insert button on the Developer tab, click the ActiveX control you want, and then drag to insert it with the size you want. If there is a problem with an ActiveX control, Word disables it to protect the program and your data. When a problem does occur, a security alert dialog box appears, displaying information about the problem and options you can choose to leave it disabled in Protected view (New!) or enable it.

Insert ActiveX Controls

Image Display the document where you want to place the ActiveX control.

Image Click the Developer tab.

Image Click the Design Mode button (highlighted).

Image Click the Legacy Tools button arrow, and then click the button with the ActiveX control you want to use.

See the next page for a list and description of each ActiveX control.

Image Drag (pointer changes to a plus sign) to draw the ActiveX control the size you want.

Image To resize the control, drag a resize handle (circles) to the size you want.

Image To add Visual Basic code to the ActiveX control, right-click the control, click View Code, or to change display properties, click the Properties button. To exit, click the Save and Close buttons.

Image Click the Design Mode button (not highlighted) to exit.

Image

For Your Information

Using Form Controls

Form controls are objects that users can interact with to enter or manipulate data. For example, you can add a Check box control to your document so that users can turn an option on and off. You can select a control from the Developer tab and drag to create the control directly on your document just like an ActiveX control. For an example on using form controls, see project downloads for Office 2010 On Demand available on the Web at www.perspection.com.

Deal with an ActiveX Control Security Alert

Image Click the File tab, and then click Open.

Image Click the File as type list arrow, and then click the document type that contains the ActiveX control.

Image If the file is located in another folder, click the Look in list arrow, and then navigate to the file.

Image Click the document with the ActiveX control you want to open, and then click Open.

Image Click the File tab, click Info, click the Enable Content button (New!), and then click Advanced Options. To enable all content (make trusted), click Enable All Content on the menu.

Image You can also click Enable Content in the Message Bar with the Security Warning.

Image If you trust the document content, click the Enable content for this session option to use it. If you don’t trust it, click the Help protect me from unknown content (recommended) option to block and disable the macros.

Image Click OK.

See Also

See “Setting ActiveX Security Options” on page 333 for more information about setting options that trigger the ActiveX security alert.

See “Setting ActiveX Control Properties” on page 425 for more information about setting ActiveX display properties.

Image

Image

Using ActiveX Controls

ActiveX Controls

Image

Setting ActiveX Control Properties

Every ActiveX control has properties, or settings, that determine its appearance and function. You can open a property sheet that displays all the settings for that control in alphabetic or category order directly from Word. The ActiveX controls appear in the Properties window in two columns: the left column displays the name of the control, and the right column displays the current value or setting for the control. When you select either column, a list arrow appears in the right column, allowing you to select the setting you want. After you set properties, you can add VBA code to a module to make it perform.

Set ActiveX Control Properties

Image Click the Developer tab.

Image Click the Design Mode button (highlighted).

Image Select the control whose properties you want to modify.

Image Click the Properties button.

Image To switch controls, click the Controls list arrow (at the top), and then select the one you want.

Image Click the Alphabetic or Categorized tab to display the control properties so you can find the ones you want.

Image Click the property box for the property you want to modify, and then do one of the following:

Image Type the value or information you want to use, such as the control name.

Image If the property box contains a list arrow, click the arrow and then click a value in the list.

Image If a property box contains a dialog button (…), click it to open a dialog box to select options or insert an object, such as a picture.

Image When you’re done, click the Close button on the Properties window.

Image Click the Design Mode button (not highlighted) to exit.

Image

Adding VBA Code to an ActiveX Control

After you add controls and set properties, you can add VBA code to a module to determine how the controls respond to user actions. All controls have a predefined set of events. For example, a command button has a Click event that occurs when the user clicks the button. When you select a control in Design Mode and then click the View Code button, the Visual Basic Editor opens with a Code window, displaying the start of a procedure that runs when the event occurs. The top of the Code window displays the active object and event procedure. The Object list displays the ActiveX control, such as CommandButton1, and the Procedure list displays the trigger event, such as Click.

Add VBA Code to an ActiveX Control

Image Click the Developer tab.

Image Click the Design Mode button (highlighted).

Image Select the control to which you want to add VBA code.

Image Right-click the control, and then click View Code.

The Visual Basic Editor window opens.

Image To show the Properties window, click the Properties window button.

Image To help with scripting commands, click the Object Browser button on the toolbar.

Image Click in the Code window between the beginning and ending line of the procedure, and then type VBA code to perform the task you want.

The Object list is set to CommandButton1, and the Procedure list is set to Click.

Image When you’re done, click the Save button on the toolbar.

Image Click the program Close button.

Image Click the Design Mode button (not highlighted) to exit.

Image

Playing a Movie Using an ActiveX Control

Although you cannot insert a Flash movie into an Word document, you can play one using an ActiveX control and the Flash player. Before you can use the control, the ActiveX control and Flash player need to be installed on your computer. You can get the ActiveX control at http://activex.microsoft.com/activex/activex/. To play the Flash (.swf) movie, you add the Shockwave Flash Object ActiveX control to the document and create a link to the file. If a movie doesn’t play, check ActiveX security options in the Trust Center in Word Options.

Play a Flash Movie

Image Save the Flash file to a Flash movie file (.swf) using the Flash software.

Image Click the Developer tab.

Image Click the Design Mode button (highlighted).

Image Click the Legacy Tools button, and then click the More Controls button.

Image Click Shockwave Flash Object.

Image Click OK.

Image Drag to draw the movie control.

Image Right-click the Shockwave Flash Object, and then click Properties.

Image Click the Alphabetic tab.

Image Click the Movie property, click in the value column next to Movie, type full path and file name (c:MyFolderMovie.swf), or the URL to the Flash movie you want.

Image To set specific options, choose any of the following:

Image To play the file automatically when the document appears, set the Playing property to True.

Image To embed the Flash file, set the EmbedMovie property to True.

Image When you’re done, click the Close button.

Image Click the Design Mode button (not highlighted) to exit.

Image

Image

Changing the Document Information Panel

The Document Information Panel helps you manage and track document property information—also known as metadata—such as title, author, subject, keywords, category, and status. The Document Information Panel displays an XML-based mini-form using an InfoPath Form Template (.xsn) file developed in Microsoft InfoPath. By using an XML InfoPath form, you can create your own form templates to edit the document property data and perform data validation.

Select a Document Information Panel Template

Image Click the Developer tab.

Image Click the Document Panel button.

Image Click Browse, locate and select the custom template you want, and then click Open.

Image URL. Short for Uniform Resource Locator. The address of resources on the Web.

http://www.perspection.com/index.htm

Image UNC. Short for Uniform or Universal Naming Convention. A format for specifying the location of resources on a local-area network (LAN).

\server-nameshared-resource-pathname

Image URN. Short for Uniform Resource Name.

Image Click the Display by default list arrow, and then select the default properties you want.

Image Select the Always show Document Information Panel on document open and initial save check box.

Image Click OK.

Image

..................Content has been hidden....................

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