Using Fields in Microsoft Word 2002

advertisement
Using Fields in Microsoft Word 2002
Introduction
Fields are used in a document to generate information which needs to be
changeable. Whenever you add page numbering to a document, a page
field is inserted into the header or footer. You might also add a date field,
either in a header/footer (to indicate when the document was last printed) or
to a letter template (to save you typing in today's date each time you want
to send out a letter). Fields are also used to create an index or table of
contents and in mail merge, to pick up information from a data source. You
can also use fields to insert document information (such as the author or file
name), to perform calculations, to create links and references to other
documents or items, and to perform many other special tasks.
Normally you will not be aware that a field exists. They can be viewed by
pressing <Alt F9>, as you will see later. The special field code is then
displayed enclosed by curly brackets {}, known as braces. Sadly, you
cannot insert field braces by typing the characters on the keyboard, though
you can generate them by pressing <Ctrl F9> (if you are an expert and
know what code to type within them). Most fields can also have switches or
other options which extend their capabilities.
Simple Fields
A field code is inserted at the current typing position (the insertion point) in
a document. You must position the insertion point before you insert the
code (eg move to the very start of your document before you insert a Table
of Contents). A few field codes are automatically inserted in the correct
place for you, irrespective of the current typing position (eg page numbers).
As an introduction to fields, add page numbering to a new document:
1.
2.
3.
4.
Start up Microsoft Word with a new blank document
Open the Insert menu and choose Page Numbers...
Set the Position: to Top of page (Header) and the Alignment: to Right
Press <Return> or click on [OK] - the screen changes to Print Layout
View
A little number 1 should have appeared in grey in the top right corner of
your document (this only shows in Print Layout View). This isn't a fixed
character - it needs to change for each page. To achieve this, Word has
inserted a Page field in the chosen location. To see the field code:
5. Press <Alt F9> and note how the number is replaced by the code
{PAGE }
6. Press <Alt F9> again and the code is switched back to a number
The key combination <Alt F9> is used to display/hide ALL field codes. You
will see later that <Shift F9> can be used to display/hide a single field code.
Next, add a date and time to your document:
7. Open the Insert menu and choose Date and Time...
8. From the list of Available formats: select the second one - the day of
the week plus the date
9. Tick on the Update automatically check box then press <Return> or
click on [OK]
10. Press <Return> for a new line then repeat step 7
11. From the list of Available formats: choose the last one (the time,
including seconds) then check that Update automatically is on - press
<Return> for [OK]
12. Repeat steps 10 and 11 but this time turn off the Update automatically
check box
13. Press <Alt F9> to see the new field codes - note that Word doesn't use
a field unless Update automatically is set on
14. Press <Alt F9> again to turn off the codes
Updating Fields
Fields are updated each time you open a file containing them. They are
also updated when you preview a document. An option also allows you to
ask for them to be updated when the document is printed. If you want to
update them at other times you can do so by forcing an update, either to a
particular field or to all of them.
1. Note the time currently displayed by the (first) time field
2. Click on the [Print Preview] toolbar button then use the magnifier - you
should find the time has been updated
3. Click on [Close] to return to your document - the time is updated again
If you were to save and close the file then reopen it tomorrow, the date field
would also have changed (and the time field would show as the time you
reopened it).
Fields can be manually updated any time, either individually or all at once.
To demonstrate this, add an extra time field, as follows:
4. Either insert another time field in the same way you did earlier or
[Copy] and [Paste] the one already in your document
5. Move the insertion point into the field - use the <left arrow> key or
click on it using the mouse
6. Press <F9> to update just this field
If you want to update several fields then you must select them first. To
update all the fields in a document, select the whole document before
pressing <F9>:
7. Select the whole document by pressing <Ctrl a> - or use Select All
from the Edit menu
8. Now press <F9> - everything which is a field is updated
To turn on the option which updates the fields each time you print:
9. Open the Tools menu and choose Options...
10. On the Print tab under Printing options: turn on the Update fields
check box
11. Press <Return> or click on [OK] to turn this option on - otherwise click
on [Cancel]
Locking, Unlocking and Unlinking Fields
Sometimes you don't want the information in a field to be updated; in this
case you lock the field. You then have to unlock it when you do want it
updated. You can also permanently unlink a field. In this case the field code
is replaced by the displayed value, held as ordinary text.
1. Move the insertion point into one of the time fields using the arrow keys
or a mouse click
2. Now press <Ctrl F11> - the field is locked
3. Try pressing <F9> - you will find the time is not updated
4. Press <Ctrl Shift F11> (to unlock the field) and then <F9> - the time
now does update
Next try unlinking the field:
5. Move the insertion point back into the field as in step 1
6. Press <Shift F9> to reveal the field code
Note: Whereas <Alt F9> displays all the field codes, <Shift F9> displays
just the one (or more than one if several have been previously selected).
7. Press <Shift F9> again, to hide the field code
8. Now press <Ctrl Shift F9> to unlink the field
9. Display all the field codes by pressing <Alt F9> - you will find that this
particular time is no longer a field but is now ordinary text (which no
longer updates)
10. Hide the codes by pressing <Alt F9> once more
More Complex Fields and On-line Help
There are numerous other fields which can be inserted into a document, as
you will see in a minute. You can also add switches to the field codes
(including page, date and time fields) to set certain attributes. This next
exercise shows you how to add such fields to a document. Example
exercises using some of the fields are given at the end of this document.
No matter which field you want to add to a document, you must first move
the insertion point to the position required:
1. Move to the end of your document (press <Ctrl End>) then press
<Return> for a new line
2. Open the Insert menu and choose Field...
The Field dialogue box will open:
Currently, all the available fields are listed in the Field names: box. If you do
not want to see the entire list, but only want to see fields in one category,
for example Date and Time, then you can choose the required category
from the Categories: box (above Field names:.
If you click on a field name, a brief description of what the field does is
shown towards the bottom of the box. Below that, the [Field codes] button
can be used to help you with the syntax (precise format) of the field - you
will see how this works later.
3. Open Categories: and choose Date and Time - then select Date in
Field names:
4. Click on the [Help] button - the ? to the left of the [Close] window
button (the mouse cursor then becomes a question mark)
5. Click in the Field names: box and help will activate for the selected field
- ie Date
The help window gives you much more detailed information about how the
Date field works. In particular it tells you what switches can be added to the
field code and what effect these have. The \@ "Date-Time Picture" is the
important switch - it determines the date format (eg whether it is shown in
full or abbreviated). To get further help on this:
6. Click on Switches button at the bottom of the Help information
7. Now click on the Learn more about date-time picture switches link
You now have further links to Month(M), Day(d), Hours(h) etc. Explore
some of these links to see how the codes work.
8. Once you have finished reading, [Close] the Help window
9. In the Field window in Word, click on Field Codes then on Options... the following window appears:
9. On the General Switches tab, select the dd MMMM yyyy code then click
on [Add to Field] - if you inadvertently select the wrong code just click
on the [Undo Add] button
10. Press <Return> (or click on [OK]) twice to add the field to your
document
The date will appear in the chosen format.
Typing in and Editing Field Codes
Microsoft Word lets you type in the field codes directly but only if you use
the special insert empty field key combination of <Ctrl F9>. You can also
edit the field codes, if you need to.
1. Press <Return> for a new line at the end of your document
2. Press <Ctrl F9> - field code braces should appear
3. Inside the braces type date
4. Press <F9> and today's date should appear in the default style
dd/MM/yy
To edit the date field code and add a switch:
5. Press <Shift F9> to display the field code
Note: Normally you would now type in the switch, but as you are not
familiar with these, display all the codes and use them as examples:
6. Press <Alt F9> to display all the field codes
7. Move the insertion point to the end of the new date field, immediately
before the final brace
8. Type \@ "ddd dd-MM-yy"
9. Press <Alt F9> to hide the field codes then <F9> to update the new
date field
The date should now be displayed in the specified format, starting with the
abbreviated weekday followed by a numeric date separated by dashes.
This format is not one which can be found in the standard list - you have
created your own customised one. For practice, try modifying it again:
10. Press <Shift F9> to display the field code
11. Edit the current switch to read \@ "dddd, dd'th' MMMM yyyy
12. Press <F9> to update the field result
Not only is the month spelt out in words and the year shown in full but you
have also added th to the date. Anything enclosed in single quotes within
the Date-Time Picture code appears as typed.
Displaying Fields with Shaded Backgrounds
Some people like to distinguish between normal text and field-derived text
in a document. You can, if you want, arrange to have fields displayed with a
shaded background. To do this:
1. Open the Tools menu and choose Options...
2. On the View tab, under the heading Show, set the Field Shading option
to Always
3. Press <Return> or click on [OK]
You will now find that any text in your document which is based on a field
code has a shaded background. To turn the shading off again:
4. Repeat steps 1 to 3 as above but at step 2 set Field Shading to When
selected
The other option, Never turns shading off completely but is generally not
recommended.
Examples of using Fields
Example 1: Counting the Number of Words in a Document
When you are writing an essay and have a word limit, you may or may not
be aware that you can find out from Word how much you have written. This
can be obtained using the Properties command in the File menu. It's also
available as a field code, which can be added to your document. This can
then be updated whenever you want a fresh word count. A good place to
position this is a couple of blank lines below the end of your typing:
1. Using any existing document, move to the end (<Ctrl End>) then press
<Return> twice
2. Type Word count then open the Insert menu and choose Field...
3. Select the Category: Document Information and then the Field name:
NumWords
4. Press <Return> or click on [OK] and the current word count will be
shown
5. Move up to the end of your text and type some more words
6. Move the insertion point into the word count number and press <F9>
for an updated count
When you have finished writing your essay, you can delete the line giving
the word count.
Example 2: Creating a Drop-Down AutoText List
AutoText can be a very useful facility when you are typing documents in
which the same word or phrase is repeated many times. Sometimes, you
may have a document or template in which the words which appear at a
particular place are from a fixed list. An AutoText List field allows you to
select the required text from a pop-up list. To achieve this, you must define
each AutoText list entry in a specially-named style.
Begin by defining the entries required. In this example, you are going to
create a list of students:
1. Start with a new blank document (press <Ctrl n>)
2. Click in the [Style] box, after the word Normal, and type in a new style
name eg students (or something similar) then press <Return>
3. Type in the first member of your list, eg Chris Smith, then drag
through to select it
4. Open the Insert menu and choose AutoText followed by New... - or
use <Alt F3>
5. Press <Return> or click on [OK] to create the AutoText entry
6. Repeat steps 3 to 5 for further members of the list - you'll need at least
two entries
Having created the list of students, you can start to use it in an AutoText
List field:
7. <Delete> the list and check the [Style] is back to Normal
8. Start typing your document - eg Next week's seminar will be given
by
9. Open the Insert menu and choose Field...
10. Under Categories: choose Links and References and in Field names:
select AutoTextList
11. Click on [Field Codes] then, in the box provided, click after
AUTOTEXTLIST and type "student name" (for a prompt)
12. Click on [Options...] and on the Styles tab select students and [Add
to Field]
13. Click on [OK] twice to insert the field code - the student name prompt
is displayed
Whenever you want to substitute the prompt by a member of the list:
14. Right click on the prompt to display the AutoText List and choose the
required student
15. You can select a different student simply by right clicking on the field
again
Example 3: Prompting Users to Enter Information
By adding Ask and/or Fill-in fields to a document or template you can insert
information via dialog boxes. The main difference between the two is that
Fill-in data can only be used once, whereas Ask stores the data in a
bookmark, which can be used over and over again via a Ref field. Fill-in
fields activate each time a document is opened; Ask fields have to be
updated manually.
Ask and Fill-in fields are frequently used in mail-merge documents.
1. Start with a new blank document (press <Ctrl n>)
2. Open the Insert menu and choose Field...
3. Under Categories: choose Mail Merge and from the Field Names:
select Ask
Note the format required by this field - you have to supply a Prompt and a
Bookmark
4. In the Prompt: box type What is your name?
5. In the Bookmark: box type xxxx then click on [OK]
The bookmark acts as a variable (a place in the computer to temporarily
store some information). You have named this one xxxx. A dialog box now
appears, asking you to supply a value for the bookmark using the prompt
you have just typed in.
6. Reply to the question then click on [OK] - the name is stored in the
bookmark xxxx
7. Start typing your document, pausing when you need to insert the Ask
field - eg type Dear
8. Now open the Insert menu and choose Field...
9. Under Categories: click on Links and References and from the Field
Names: select Ref
10. Under Field properties select the Bookmark name xxxx
11. Click on [OK] and the name is displayed
12. Continue typing your document, repeating steps 8 to 11 each time you
want the field shown
When you have finished your document you might want to print out a copy.
You might then want a duplicate document but addressed to someone else:
13. Press <Ctrl a> or use Select All from the Edit menu to select your text
14. Now press <F9> to update the field codes
15. Supply a different name then click on [OK] - the new name will appear
wherever a field code has been used
The above example offers you a controlled method of find and replace.
Only where a field code has been used will the text be updated - where the
same text is typed in directly it will not be replaced.
This next example uses a Fill-in field to supply additional data to a mail
merge. It lets you supply an interview time for letters to be sent out to
candidates held in a database.
1. Start with a new document - press <Ctrl n>, if necessary
2. Open the Tools menu and select Letters and Mailings then
MailMerge Wizard... - the Task Pane appears
3. Under Select document type choose Letters then click on Next: at the
foot of the Task Pane
4. Under Select starting document choose Use the current document click on Next:
5. Under Use an existing list click on Browse
6. Open the file D:\user\advanced.xls by changing drives to User (D:),
opening folder user, selecting advanced.xls and pressing <Return>
for [Open]
7. In the Select Table window, choose Students.$ then click on [OK]
twice to have access to all the data fields
You now have to type in your invitation to interview letter. First, turn on the
MailMerge toolbar:
8. Open the Tools menu, choose Letters and Mailings then Show Mail
Merge Toolbar
9. Type Dear then, using the [Insert Merge Fields] button, add Title and
Surname
10. [Close] the Insert Merge Fields window then add a space to separate
the two fields
11. Press <End> then <Return> twice then type You are invited for
interview at
12. Now open the Insert menu and choose Field...
13. Under Categories: choose Mail Merge and from the Field Names:
select Fill-in
14. In the Prompt box provided, type Enter the interview time
Note: You can set a default value for this field in the Default response to
prompt: box.
15. Click on [OK] twice, leaving the interview time value empty
16. Finish off the letter by typing a full-stop, and adding Yours sincerely
on a new line
Your letter is now complete - a real one would be much longer. It's now time
to mail merge:
16. Click on the Merge to New Document button on the Mail Merge
toolbar
17. There's no need to merge all 390 records here, in the To: box type 3 click on [OK]
18. For each candidate type in the time: eg 9:30 , 10:00 and 10:30
The mail merge will now be carried out, with the appropriate times inserted
in the three letters.
Example 4: Keeping "Boilerplate Text" Up-to-Date
Boilerplate text is text which is used again and again in a document. Good
examples are a carefully-worded conditions clause or a complex clause in a
legal document. It is possible to use fields to keep this information up to
date. These act rather like find and replace except that with complicated
text they are much easier to use. Often such text needs to be reworded
several times before it is finalised.
To create boilerplate text you use the AutoText facility linked to a special
AutoText field:
1. Start with a new document - press <Ctrl n>, if necessary
2. Begin by typing the current wording: eg To be approved by the Head
of Department
3. Select the current wording then open the Insert menu and select
AutoText then New...
4. Name your AutoText entry - To be approved is fine, click on [OK] or
press <Return>
5. <Delete> the words used for the AutoText entry and start typing your
document (rubbish text will do)
6. At the end of the paragraph, open the Insert menu and choose Field...
7. From Categories choose Links and References
8. In the Field names box choose AutoText
9. Under Field Properties and select the AutoText entry To be approved press <Return> for [OK]
The special clause will be displayed in your document. Type some more
paragraphs, adding the special clause where required:
10. Repeat steps 6 to 9 for further boilerplate text entries
Your document is now ready for the boilerplate text to be updated:
11. Display the current clause - start typing to be approved then when the
AutoText appears press <Return>
12. Edit the text to read: To be approved by the Deputy Head of School
or the Head of Department (or his secretary)
13. Select the amended text and redefine it as the AutoText entry - open
the Insert menu, choose AutoText then New... and use exactly the
same AutoText name (ie To be approved)
14. Click on [Yes] to redefine the entry then <Delete> the new entry
15. Finally, select the document (<Ctrl a>) and press <F9> to update the
AutoText fields
Though you may consider it a lot of effort to achieve essentially a find and
replace, some clauses in legal documents may extend to several lines of
typing.
Note: If you plan to share this document with a user who does not have the
same AutoText entries, you may want to lock the field results to prevent the
text from being changed accidentally.
Example 5: Creating Dictionary-Style Page Headers
Using fields, you can print the first and last items that appear in a list at the
top of each page - like in a dictionary or telephone directory. For example, if
you were typing out a list of references, you could have the first and last
reference that appear each page listed. This can be done as follows:
1. Start with a new blank document (press <Ctrl n>) - unless you already
have one suitable
2. Click in the [Style] box, after the word Normal, to create a new style call it listitem (or something similar) then press <Return>
3. To speed up typing, press <Ctrl 2> to double-space the list then type in
a list which stretches over two pages - a single character per line is
sufficient, eg a to z
You now need to add two special fields in the page header (or footer):
4. Open the View menu and select Header and Footer
5. Open the Insert menu and select Field...
6. Under Categories: click on Links and References and in Field Names:
select StyleRef
7. Under Style name: select listitem
8. Press <Return> or click on [OK] to insert the field
The first list entry on the page should now be shown. Continue as follows:
9. Type the word to then repeat steps 5 to 8, as above
10. Under Field options turn on Search from bottom of page to top
11. Press <Return> or click on [OK] to insert the field code
12. If required, justify the fields by clicking on the [Align Right] or [Center]
buttons
13. Finally, [Close] the Header and Footer
Note: If your new header shows no value after the word to, you have a
blank line at the end of your list on that page - <Delete> it or add another
list item.
Download