RibbonX for Dummies: Chapter 6 (Part 2) (
Page 2 of 6 )
Creating Labels
You override the Labels button on the Mailings tab for some of the same reasons
as you override the Envelopes button. Generally, you have a need to
control the output of labels on a system. When working with Ribbon applications,
it's important not to interrupt the workflow or you won't gain all the
benefits that come from the new method of creating user applications.
Working with labels is almost the same as envelopes. You still need to create
an object and set any defaults, as shown here:
' Create the MailingLabel object.
Dim MyLabel As MailingLabel
Set MyLabel = Application.MailingLabel
' Set the output type.
MyLabel.DefaultLabelName = "30 Per Page"
ADVERTISEMENT
Notice that the label isn't part of the document; it's part of the application,
which does make for some differences in printing. You select the text to print
just as you would for an envelope. However, when it comes time to print,
simply highlighting the text isn't enough. The code must provide the text to
print as input to the output method, as shown here:
' Output the label.
MyLabel.PrintOut Address:=CurrPane.Selection.Text
As with envelopes, you can print labels to a document instead of to the
printer. However, the labels appear as a separate document, not as part of the
original document. You use the MyLabel.CreateNewDocument method to
accomplish the task. As with the printed output, you must provide text as
input using the Address argument of the call.
Filling Out Forms
Forms fulfill a number of purposes — everything from requesting services to
documenting work accomplished — in organizations. In fact, many organizations
have so many forms that people create duplicates simply because they
don't know the original exists. Your organization may have four or five versions
of a single form right now, and the redundancy causes a wealth of problems.
One method of overcoming this problem is to make forms instantly
available so that users can peruse them and choose the forms they need.
Figure 6-10 shows the Forms tab described in this section.
Notice that this example, like the letter example in this chapter, follows a leftto-
right flow of events: The user selects a form, fills out the personal data,
and then provides a date. Using this application produces three results:
The user doesn't have to search for forms.
The forms contain the correct user information (making it easier to find
the user to ask questions).
The forms have a better chance of containing complete information.
Figure 6-10:
Filling out
forms isn't
a chore
when the
application
does much
of the work.
The sections that follow describe the major activities needed to make this
application work. (You can find the complete source code for this example on
the Dummies.com site at http://www.dummies.com/go/ribbonxfd.)
Creating the forms
This example includes a new feature: The forms appear as part of a gallery, as
shown in Figure 6-11. The amazing thing is that you don't have to rely on any
odd programming techniques to achieve this goal. The application relies on
some simple coding techniques and good directory organization to make this
gallery possible. The coding technique also makes it possible to add forms to the
gallery at any time without doing anything special. The application automatically
updates the gallery to reflect any new form templates added to the list.
Creating a form in Word 2007 is similar to older versions of Word, but there
are some important differences. The first difference is that the controls you
add to a form appear in a special section of the Developer tab, as shown in
Figure 6-12. You select the location of the control on-screen, and then choose
one of the controls from the list.
Figure 6-11:
The user
begins by
choosing
one of the
forms from
the Forms
directory.
The naming of controls is important when you want to create a Ribbon application
with them. For example, every form in this example that has a date
field calls it ReqDate. To set the field properties, right-click the control and
choose Properties from the context menu. The Bookmark field of the control's
Options dialog box determines the name you'll use for that control in
your code. If you want to save time and effort, using consistent names is
essential.
After you add and configure all of the controls on your form, you need to test
it. You have to protect the form in order to activate the form fields. Microsoft
has changed this functionality in Office 2007 as well. Use the following steps
to protect a form:
1. Click Protect Document on either the Developer or Review tab.
You see a list of protection options.
2. Choose Restrict Formatting and Editing from the list.
Word displays a Restrict Formatting and Editing task pane like the one
shown in Figure 6-12.
Figure 6-12:
Choose the
controls you
want to use
from the
special
Legacy
Forms
gallery.
3. Check the Allow Only This Type of Editing in the Document option.
Word activates the option and lets you choose the level of restriction.
4. Select the Filling in Forms option.
5. Click Yes, Start Enforcing Protection.
Word displays the Start Enforcing Protection dialog box, as shown in Figure 6-13.
6. Type passwords to protect your document, and then click OK.
Word activates the fields on the document so that you can test the form functionality.
You can remove document protection by clicking Stop Protection at the
bottom of the Restrict Formatting and Editing task pane. Word asks you to
provide the password you supplied earlier. After you enter the password, you
can make changes to the document again.
Make sure you save your form as a template, and not as a document. If you
save the form as a document, the application won't recognize it; even if you
do open it, the form won't create a new version of itself. The form will act as a
one-time fill-in, rather than as a means of creating multiple copies.
One of the tasks that you must perform for this example, in addition to creating
a form, is to take a screenshot of the form. The example uses the screenshot
to show how the form will appear when the user accesses it using the
gallery. The screenshot must have the same filename as the form, but with
the image extension. The example code relies on the Portable Network
Graphic (PNG) file format. However, you can easily modify the code to meet
any need.
Figure 6-13:
Type
passwords
to protect
your
document
from
change.