Professional Documents
Culture Documents
MS Office 2003 MVPs Tables
MS Office 2003 MVPs Tables
Or: I added an extra row to my table, and suddenly, all but the first row jumped to the next page Maximising the performance of Word tables How can I resize a table to fit the page's width? How to centre a left-justified table (or left or right-justify a centred one) How to fix the Word 2000+ Cell Alignment buttons How to sidestep the problems of the Word 2000 (and higher) Table Properties dialog Is there a way to add custom table formats to the Table Autoformat list? I tried to use the { =SUM(ABOVE) } formula in a table but the answer was obviously incorrect How to get a formula field to total an entire table column, even if some cells in the column contain text or are blank Floating objects in Word 2000 table cells are vertically aligned wrongly Whenever I insert a graphical object (picture, drawing object, etc.) into a Word 2000 table cell I lose the vertical formatting. The text is always aligned at the top of the cell, instead of being centered or at the bottom of the cell. Why, and what can I do about it? I have a Name column which I want to split into FirstName, LastName how can I do it? How to convert a Word table into an Access database How to use relative cell references in Word table formulas How to link a Word table with a Word graph See also the Tables section on the Macros/VBA tab
Tables and table-related fields ............................................................................... 2 Table Basics ........................................................................................................................ 6 Overview ......................................................................................................................... 6 What is a Table?.............................................................................................................. 7 Inserting a table ............................................................................................................... 8 Working in a table ........................................................................................................... 9 Tabs ............................................................................................................................. 9 Selecting text ............................................................................................................. 10 Margins and indents .................................................................................................. 10 Selecting parts of a table ............................................................................................... 10 Sizing rows and columns .............................................................................................. 11 Sizing columns using the ruler .................................................................................. 11 Sizing columns using the cell borders ...................................................................... 12 Another way to size columns and rows .................................................................... 12 Even distribution ....................................................................................................... 13 Adding rows or columns ............................................................................................... 13 Deleting rows, columns and tables ............................................................................... 13 Repeating headings ....................................................................................................... 14 Positioning the table...................................................................................................... 14 Controlling text flow ..................................................................................................... 14 Widow/Orphan control and Keep lines together ............................................... 14 Keep with next....................................................................................................... 14 Page break before .................................................................................................. 15 Performance issues........................................................................................................ 15 Advanced techniques .................................................................................................... 15 Merging cells ............................................................................................................ 15 Vertical alignment ..................................................................................................... 15 Text direction ............................................................................................................ 16 Cell margins .............................................................................................................. 16 Graphics in tables ...................................................................................................... 17 Nested tables ............................................................................................................. 17 Text-wrapped tables and frames............................................................................ 18 Tables and HTML ..................................................................................................... 19 Drawing tables .......................................................................................................... 19 Wide tables.................................................................................................................... 19 Narrow tables ................................................................................................................ 20 Changing your mind ..................................................................................................... 20 Why don't my table borders print? .................................................................................... 22 Run for the border: using borders in Word ....................................................................... 24 Borders, boundaries, gridlines ...................................................................................... 24 Access to borders .......................................................................................................... 24 Some gotchas ............................................................................................................. 28 Some disadvantages of using the Tables and Borders toolbar ...................................... 29 Drawing tables .............................................................................................................. 29 The strait and narrow: using columns ............................................................................... 32
Types of columns (tables, snaking columns, or ??) ...................................................... 32 Tabs ........................................................................................................................... 32 Tables ........................................................................................................................ 32 Text box columns...................................................................................................... 32 Snaking columns ....................................................................................................... 33 Parallel columns ........................................................................................................ 33 How many columns?..................................................................................................... 33 Getting started ............................................................................................................... 33 Planning your columns ............................................................................................. 33 What you will see...................................................................................................... 34 Completing the setup ................................................................................................ 34 Working with snaking columns .................................................................................... 34 Multicolumn sections in single-column documents ..................................................... 35 Some snaking column gotchas ...................................................................................... 35 Columns within columns .......................................................................................... 35 Footnotes ................................................................................................................... 35 Headers and footers................................................................................................... 36 Headings spanning columns ..................................................................................... 36 Summary ....................................................................................................................... 37 Keeping a table together on one page ............................................................................... 38 Maximising the performance of Word tables ................................................................... 41 As a user ........................................................................................................................ 41 In code ........................................................................................................................... 43 How can I resize a table to fit the page's width? ............................................................... 50 Word 2000 .................................................................................................................... 50 Word 97 ........................................................................................................................ 50 How to centre a left-justified table (or left or right-justify a centred one) ....................... 53 How to fix the Word 2000+ Cell Alignment buttons ....................................................... 55 Is there a way to add custom table formats to the Table Autoformat list? ....................... 58 I tried to use the { =SUM(ABOVE) } formula in a table but the answer was obviously incorrect ............................................................................................................................ 59 How to get a formula field to total an entire table column, even if some cells in the column contain text or are blank ....................................................................................... 62 Floating objects in Word 2000 table cells are vertically aligned wrongly ....................... 65 I have a Name column which I want to split into FirstName, LastName how can I do it? ............................................................................................................................... 66 How to convert a Word table into an Access database ..................................................... 69 Using Excel to transfer data between Word and Access: ............................................. 69 Using Word Only .......................................................................................................... 69 How to link a Word table with a Word graph ................................................................... 75
Table Basics
Article contributed by Suzanne
1. 2. 3. 4. 5.
Overview What is a Table? Inserting a table Working in a table Selecting parts of a table
9.
techniques
14. 15.
16. Changing
your mind
Overview
If you come to Word from a typewriter background, you are probably used to setting up tabular material using tabs. The very word tab is short for tabulator, and tabulator stops on a typewriter are used in tabulation, that is, making tables. So your first impulse when you need to make a table in Word may be to use tabs. Sometimes this is an acceptable (or occasionally, even the best) way to go. For a simple table with short entries, and very few rows, setting tab stops can be quick and easy, and Word allows you to drag them around until the text lines up where you want it. If you do use tabs to create a table, be sure you use them properly; in particular, never use the built-in tab stops; always create your own. For tips on this subject, see Setting tabs (Or how to prevent tabbed paragraphs from going all over the place when pasted between documents). Like other word processors, however, Word offers a very easy way to create tables that use true rows and columns, as opposed to simply containing tabular text. Whenever your needs are less simple for example, whenever the text in any column of your table might need to wrap to the next line, or you need vertical table borders, or your table might span more than one page and need a continuation header, or if you might ever conceivably need to change the column order you
should use Words built-in Table feature. Note that you can convert tabular text into a Word Table in one step, provided your tab stops were set properly, by selecting Table | Convert Text to Table and pressing OK. See also Changing your mind. Many people who are not familiar with using true Tables try to use text boxes to simulate the appearance of a table with borders; or sometimes even to draw their borders using horizontal and vertical drawing lines. As well as making life far more difficult than it need be during the design of the table, this also creates a maintenance nightmare, should anyone need ever need to add, delete or amend the data later, or to paste the table into another document. There is really no circumstance in which using text boxes or drawing lines to create tabular information is ever preferable to using a table. Lets look at what Word's Table feature does.
What is a Table?
How is a Table different from a table of tabbed text? As you know, you can arrange tabular material using tabs. For example, you can use a combination of left-, center-, decimal-, and rightaligned tab stops, in combination with horizontal paragraph borders, to create a text-based table such as the following (shown with non-printing characters displayed, so you can see how it was created):
Figure 1
Notice (in Figure 2) what can happen when you add some text to one of the lines, because of the lack of support for word-wrapping:
Figure 2
Selecting a single column is possible (hold the Alt key down while you drag with the mouse); but is much more difficult than if a Word Table had been used; and it is not possible to have a running header, should the table span two pages. But suppose the tabular material is more complex. For instance, suppose you have paragraph text to be placed in side-by-side columns, as in the following example: Comment, Statement, or Assertion Response or Rebuttal
Mr. Doe accepts the appraisal as conform[ing] in most categories to R41b and the Standards of Professional Practice in place at the date of the appraisal. It is not adequate for an appraisal to conform in most categories. This is like saying that a driver generally follows traffic laws but will intentionally run a red light or stop sign. The report states: I cannot render an opinion as to the accuracy of the valuation, and there are indications that the value indicated in the report is reasonable. This implies both that Mr. Doe agrees with the value estimate and that there are or could be indications that the value indicated is not reasonable.
Figure 3
When you use tabs to create such a table, each row of the table (or sometimes the whole table) is a single paragraph. If you tried to type text such as the above using tabs (and I have actually seen this done!), you would have to break the paragraphs up into fragments that would fit on each line. If the text had to be edited, it would be a nightmare. But when you use Words Table feature to create a table, Word creates a cell for each intersection of a row and column. Each cell contains a separate paragraph (or can contain several paragraphs); and the text in the cell can wrap independently of the rest of the table. So whenever your tabular material contains text that must wrap to the next line a Word table is far more satisfactory than a tabbed table.
Inserting a table
Inserting a table is easy. If you choose Insert Table from the Table menu (or in Word 97, select Insert from the Table menu), you can choose the number of rows and columns you want your table to start with. (Don't ever select Table | Draw Table, for the reasons discussed below under Drawing tables.) Or you can use the context-sensitive Table button on the Standard toolbar; when you click on this you will see a flyout table grid on which you can use your mouse to select the desired number of rows and columns. Although the flyout (see Figure 5) shows five columns and four rows when you first click on it, you can drag to select more rows and columns; the maximum number depends on your window size, your screen resolution, and the relative placement of the button on your toolbar that is, how far you can drag before reaching the side or bottom of the Word window.
The number of columns is all that really matters because you can add rows to the table as you go: whenever you
press Tab at the end of the last row of the table a new row is created.
Figure 4: The Table button on the Standard toolbar is context-sensitive, its appearance and functionality being determined by what is selected
For this reason I usually just create two rows, one for the table headings and another for the first row of text. If applying grid borders, it's best to start with three rows, so that you can apply one grid to row 1 and a separate grid to rows 2-3; but you would almost never need to start with more than that. When you first insert the table, it will have a -point border around the cells, creating a grid.
Working in a table
You can put almost anything in a table that you can put in normal document text, and you can format table text the same way you would ordinary text paragraphs. The best way to do this, of course, is with styles (you may want to define special styles for use in tables, and Word 2002 even allows you to define special styles for an entire table), but you can apply font and paragraph formatting the same way you normally do. There are just a few things that work differently in tables.
Tabs
When you tab in a table, you go to the next cell (Shift+Tab takes you to the previous cell). This makes it easy to work in tables because you dont have to use the mouse to move your insertion point. But you can still set tab stops in table cells; the trick is that you have to use Ctrl+Tab to tab to them. The exception to this rule is the decimal tab. When you set a decimal tab stop in a cell, the text aligns on it automatically (provided it is left-aligned or justified to begin with; any other
Selecting text
If youre used to selecting a line of text by clicking to the left of it or a paragraph by double-clicking to the left of it, youll find that you cant do this in a table. Whenever you point to a cell and click, you select the entire cell. But you can still select text by dragging, and you can select a sentence using Ctrl+click or a paragraph by triple-clicking in it. And if you normally select text using keyboard shortcuts, these will still work.
10
the NumLock Key. Unfortunately, if your keyboard does not have a numeric keypad, or you do not have access to it, there is not, so far as we have discovered, an alternative mouse shortcut to select the entire table. Double-clicking while pressing Alt will still select the table but will also open the Research pane. If the Research pane doesnt insist on trying to connect to the Internet, you may still find it easier to Alt + double-click, close the task pane, and keep working than to work down through several menu levels (Table | Select | Table). In Word 2002 and above you can select non-contiguous rows and columns by pressing Ctrl while selecting rows or columns after the first.
11
For example, if you have a column of width 1" (2.54cm), and if the Space between columns is set to 0.15", or 0.38cm, (the default), then the column width displayed on the ruler when you hold the Alt key down will be 0.85" (2.16cm). To find out the Space between columns setting using the Table Properties dialog in Word 2000 and higher, click the Options button on the Table tab, and add the Left and Right cell margin measurements although that isn't always accurate, as it only displays to two decimal places. For instance, if the Space between columns is set to 0.15", the Left and Right cell margin measurements on the Table Properties dialog both display as 0.08" instead of 0.075". A better way of finding out the true measurements is covered at: How to sidestep the problems of the Word 2000 (and higher) Table Properties dialog. Alt+Ctrl+click and drag: Same as Ctrl+click and drag except that the ruler displays dimensions. Alt+Shift+click and drag: Same as Shift+click and drag except that the ruler displays dimensions. (But see above rider.)
appearance, you can click and drag a column boundary. You have the same six combinations as above, but, just to be totally confusing, simple click and drag and Shift+click and drag (and Alt+click and drag and Alt+Shift+click and drag) are reversed in their functionality. It is possible that some users actually memorize or remember what these various combinations do, but I personally just keep trying one after the other (with Undo in between) until I get the one that does what I want! Sizing rows You can also adjust row height either using the vertical ruler or by dragging the cell boundaries, but only in Page/Print Layout view. Pressing Ctrl while you drag sets the row to an Exact, or fixed, height, so that if there is too much text in the cell to fit, the surplus text will be hidden (setting exact row heights is particularly useful for forms). If you don't use the Ctrl key, the row height is set to At least the measurement you chose, so the row will expand in height if needed, to fit the text in the cell, but will not contract below the minimum height you set. Pressing Alt while you drag causes the ruler to display dimensions but prevents you from setting an Exact height, even with the Ctrl key held down.
12
another measurement, followed by the measurement unit such as 2" or 5 cm and Word will convert it to points. Word 2000 and 2002 have a Table Properties dialog (accessible via the right-click shortcut menu) that has Table, Row, Column, and Cell tabs. On the Table tab you can set a preferred width for the entire table; this can be set in your default measurement unit (inches, centimetres, or whatever else you have set on the General tab of Tools | Options), or you can set the Measure in dropdown to percent, and set it to any percentage of the editable page width you wish. If you set it to 100%, it will always maintain full margin width, no more and no less (for coverage of the nearest equivalent in Word 97, see: How can I resize a table to fit the page's width?). On the Row tab of the Table Properties dialog, you can set Auto, At least, or Exactly heights. On the Column tab you can set a preferred width for the current column, although unfortunately, in Word 2000 and higher, preferred width does not mean actual width, and setting the column width using the dialog usually gives unexpected results; dragging the columns to set their widths is generally much more reliable. Fortunately, you can sidestep the unreliability of the Word 2000 and 2002 Table Properties dialog see How to sidestep the problems of the Word 2000 (and higher) Table Properties dialog for details.
Even distribution
An extremely useful option introduced in Word 97 is the Distribute columns evenly command. If you select two or more adjacent columns, right-click, and choose this option, the total width of the combined columns will be divided equally among them so that they are the same width.
To delete a row or column, select it, right-click, and choose Delete rows or Delete columns. (You can also use Cut.) To delete an entire table, select it and use either Cut or Table | Delete Table; in Word 2000 and higher, you can also delete a selected table by pressing Backspace.
Repeating headings
If your table is longer than one page (or continues onto a second page, regardless of length), you can make your headings automatically repeat on the following page(s). In Word 97 and earlier, select the row(s) you want to repeat and check Headings on the Table menu. You can repeat more than one row, but they must be the top rows of the table (you cant skip any rows). In Word 2000 and higher, select the desired heading rows and check Heading rows repeat on the Table menu. (There is also a check box on the Row tab of the Table Properties dialog for Repeat as header at the top of each page.)
14
Performance issues
See: Maximising the performance of Word tables.
Advanced techniques
All of the above is more than enough to get you started creating basic tables, but Word allows you to do a lot of other fancy things in tables.
Merging cells
All versions of Word allow you to merge and split cells horizontally. Word 97 and above also allow you to merge and split cells vertically (and also to adjust cell widths independently of the column width). To merge cells, select the cells to be merged (combined), right-click, and choose Merge Cells. Although in Word 97 and above you can merge cells both horizontally and vertically, there are limitations. You cannot create an L-shaped cell. If two cells are merged vertically, then the combined cells cannot be merged horizontally with a single cell but only with the two adjacent cells. But even in earlier versions, where you cannot merge cells vertically, you can often create the appearance of merged cells by applying borders selectively. In Word 95 and earlier, if you merged two columns, you in effect merged the two cells in each row of the two columns; in Word 97 and later, unfortunately, you merge the two entire columns into one big cell, which isnt very helpful! You can get around this, however, by using the Eraser tool on the Tables and Borders toolbar; if you use it to erase the border between two columns, the rows remain intact.
Merging should be approached cautiously and conservatively. Dont merge cells horizontally until you are sure the column widths are final. The reason for this is that selecting and sizing columns is complicated by merged cells. And dont merge cells at all if you dont have to. If you can achieve the same effect by omitting borders, do that instead. Merging cells makes a table more complex and susceptible to corruption, which is reason enough to avoid it except when absolutely necessary.
Vertical alignment
By default Word places text at the top of a table cell (subject to any Spacing Before you have applied to the paragraph). But sometimes, as in a price list, for example, you may want to align text at the bottom of the cells. In Word 97, you can choose Top, Center, or Bottom alignment for all the text in a given cell. This command is on the right-click shortcut menu when the insertion point is in
15
a given cell. (By default it does not appear when you have an entire row selected, but you can add it through Customize.) It also appears on the Tables and Borders toolbar. (Although this feature is very useful, if you must share documents with users of versions earlier than Word 97, keep in mind that the alignment will not be retained because it is not supported in previous versions. In those versions you will need to use Spacing Before or line breaks to position text other than at the top of a cell.) Word 2000 and higher have substituted a table alignment palette that displays nine combinations of vertical and horizontal alignment. If you have defined the horizontal alignment as part of your style, you will prefer the Word 97style vertical alignment menu. You can restore it following the directions in How to fix the Word 2000+ Cell Alignment buttons.
Text direction
In Word 97 and above, you can rotate text in a table cell 90 degrees right or left. The text rotation is displayed only in Page/Print Layout view and applies to all the text in the cell. This is useful when you have long headings for narrow columns. The Text Direction command is on the rightclick shortcut menu when the insertion point is in a cell, as well as on the Format menu and the Tables and Borders toolbar. (Again, keep in mind that this feature is not supported in earlier versions.) When text is rotated, the horizontal and vertical alignment buttons are rotated accordingly, which can be a little disconcerting.
Figure 8: The Cell Alignment buttons when the selection is in a normal table cell (left), and in a cell in which the text has been rotated (right)
Cell margins
Space around the text in cells is achieved in several different ways. In Word 97 and earlier, the left and right cell margins are determined by the Space between columns measurement on the Column tab of Table | Cell Height and Width. Word 2000 and higher, instead of the Space between columns setting, have Cell margins settings that can be established as a default for the entire table or specified for individual cells. Set default cell margins for the entire table in the Table Options dialog accessed via the Options button of the Table tab of Table Properties. Set margins for a specific cell (or selected cells) in the Cell Options dialog accessed via the Options button on the Cell tab. You can also still use paragraph indents in cells, but this should not be necessary except when you want one paragraph indented more than the rest in a single cell. The default setting for the Space between columns is 0.15", or .38cm, resulting in 0.08" left and right margins being displayed Under Table | Properties | Options in Word 2000 and above, if you use inches (although the true left and right margins are actually 0.075"); or 0.19cm being displayed if you use centimetres. It can be reduced to 0" (no space between columns) or increased as desired. This setting applies to all cells in the table, but you can increase cell padding using paragraph indents. You can also reduce the effective cell margin in a given cell by setting negative paragraph indents; this technique should be used sparingly, however, since it can have very odd results when the column width is changed. In Word 97, top and bottom margins (if any) must be created by applying Spacing Before and/or
16
After to the paragraphs in the cell. In Word 2000 and higher, you can set Top and Bottom cell margins by selecting Table | Properties | Options but note that any such margins will disappear if a Word 97 user opens your document. Word 2000 and above also support something quite different, rather confusingly called Spacing between cells, also accessible via Table | Properties | Options. This setting seems to be there for the sake of HTML compatibility (it is equivalent to HTML's cellspacing). It creates an ugly effect whereby, instead of adding cell margins, as the cell margins settings do, it adds white space in the middle of the cell borders, splitting each border in two: This table has cellspacing applied cellspacing is not really appropriate for use in Word.
Figure 9
Graphics in tables
In Word 97 and earlier versions, floating graphics and tables are not compatible. You can insert pictures as inline objects (that is, objects in the text layer) in a table, but you cant wrap text around them. Sometimes you can fudge by splitting a cell and putting a graphic in part of it and text in the other (as has been done with many of the graphics in this article); but this is not always satisfactory. And you cant put Words drawing objects (AutoShapes, text boxes) in Word 97 tables at all unless you first convert them to inline objects (using Copy, then Paste Special as Picture, with the Float over text check box cleared). In Word 2000 and above, you can insert floating images in table cells. Floating images are those with a wrapping style other than In line with text (on the Layout tab of the Format Picture dialog). Images that have Behind text or In front of text wrapping can float freely over the table without being confined within a table cell. An image with Square, Tight, Through or Top & bottom wrapping will be confined to a cell. If the image is resized to a larger width, the table cell will adjust to accommodate it. Having said that, though (and as discussed in the article The draw layer: a metaphysical space), it is best to use floating graphics only when they are really needed; and in long documents it is best to avoid them altogether, other than in Headers, Footers, and on the cover page. And if you do need to use floating graphics in a table, it is usually best to ensure that their anchors are placed outside the table see, for example, the article: Floating objects in Word 2000 table cells are vertically aligned wrongly.
Nested tables
In Word 2000 and higher versions, you can embed (nest) a table within a cell of a larger table (for an example, imagine the thumbnails of the previous and following months that might appear in the unused day spaces of a monthly calendar). Nested tables make a document much more complex, can slow Word documents down dramatically; and the behavior of the tab key is changed. The existence of nested tables also complicates working with ordinary tables: because now you can insert tables within one another, you may see new pasting behavior when you paste tables. There are specific rules for this behavior, but in general they are pretty logical, though usually irritating in practice. To summarize, you can paste equal numbers of cells as cells, but if you try to paste several cells into a single cell, they will be pasted as a nested table. To prevent this from happening, drag and drop your cells instead of pasting them; or select Edit | Paste Special as Formatted Text (which is the only workaround when pasting from Excel into a Word table).
17
Well-designed web pages would be impossible to create without nested tables, because the only way to set the width of a web page is to put all your text (and any tables within the text) inside a fixed width table cell; but nested tables are rarely either appropriate or useful in Word: avoid them when you can. If you do use nested tables, you will get unpredictable results if the documents are ever opened in Word 97 or earlier.
18
needed is one thing, but it should never be used if not needed, and therefore the ease with which wrapping can be accidentally applied is very unfortunate. So it is usually much better to do things the old-fashioned way, even in Word 2000 and above, and insert a proper frame (just select the table and click the Insert Frame button), rather than using the invisible frame that gets inserted when you turn text-wrapping on. The functionality is identical, but a visible frame makes it far easier to see what's going on than an invisible one does; and makes for far more maintainable documents. See also: How can I add the Insert Frame command to the Insert menu?
Drawing tables
The Tables and Borders toolbar has a Pencil tool that allows you to draw a table (also accessible via Table | Draw Table). The premise is that you can easily create custom-sized cells without the bother of merging or splitting. The reality is that you can easily get yourself into a whole pile of trouble, especially when you start trying to size the cells or use the Eraser; and also, if you use this tool you will inevitably make your tables unnecessarily complex without realizing it. It actually takes a great deal of skill not to make a mess of your tables, if you use the pencil tool. I have had to sort out the mess made by many users who have used it, and my advice about drawing tables therefore is: Dont.
Wide tables
Occasionally you will need to create a table that is just too wide to fit between the margins of a normal portrait page. In this case you have several options: 1. The most straightforward approach is to insert a landscape page or pages in order to make the table wider. Although this method has its drawbacks, especially if you need to preserve a portrait header and/or footer (see How can I create a landscape section and still have a portrait page number?), its the conventional way of tackling the problem. It may be possible to rotate the table layout, swapping headings and stubs, so that it is longer than it is wide, but this doesnt always help if the cell text itself is wide or if this distorts the table logic. It is conceivably possible to effectively rotate the table itself, swapping headings and stubs and then rotating the text 90 degrees, but this is a gargantuan mental effort, and rotating text adds complexity to the document. If the table will not need editing, you could create it as a separate landscape document and then use Copy and Paste Special: As Picture for one page at a time. The inserted picture can then be rotated.
2.
3.
4.
Needless to say, methods 2, 3, and 4 are offered in a purely academic spirit; in most cases the first one is what you will use. Users, especially those more at home in Excel, sometimes ask whether it is possible to split a table across two portrait pages. There is no built-in way to do this in Word. You can manually set up a broadside table to spread across two facing pages, but you have to construct it by hand, and if row heights are likely to vary, youll need to make them all Exact so that they will match from one page
19
to the next. Again, this requires a lot of mental effort and manual tweaking, so generally it is better to rethink the table and either divide it into two or more tables or run it broadside on a landscape page or pages.
Narrow tables
Sometimes you will have a long, narrow table that would be much more efficiently displayed in two or more columns. There is no reason not to do this. It is generally easier if you set up the column formatting before inserting the table so that the inserted table will be the width of the column rather than the full margin width. You can create a multi-column section manually, by inserting section breaks and then applying the desired column formatting to each section, but you can also get Word to do the work for you. At the end of the text preceding the multi-column section, press Enter twice to create two empty paragraphs. Select the first one and use Format | Columns (or the Columns button on the Formatting toolbar) to select two or more columns. Word will insert the necessary Continuous section breaks above and below this paragraph, where you can now insert your table. Because you have a Continuous section break at the end of the multi-column section, Word will automatically balance the columns (unless you tell it not to with the appropriate setting in Tools | Options | Compatibility). This can be distracting when you are creating the table because every time you add a row, the table shifts from one column to another. If you work in Normal view, this will not be a problem. (For more on working with columns, see The strait and narrow: using columns.) When you have a table divided across multiple columns, you will find that heading rows repeat at the top of each column. But you may wonder how to force table rows into the next column. If you insert a column break (Ctrl+Shift+Enter or Insert | Break: Column), the headings will not repeat, and there is no Column break before property for paragraphs. In this situation you will have to apply Keep with next to the rows you want to move to the next column. If your table is very well defined and there is no possibility that you will need to add or delete rows, and if all the rows are of uniform height, you can create the appearance of a multi-column table without actually using snaking columns. Just create a table with twice as many columns as you need, plus one. Use the centermost column (with borders removed if youre using borders on the rest of the table) as the gutter between your columns and fill the two sides of the table just as if the table on the right were a continuation of the one on the left.
20
21
Barnhill
If most of the borders are okay and just the bottom border (or right border on a landscape page) is not printing, the problem is probably that they are in your printers unprintable area. If the borders dont print at all, in rare cases the problem may also be due to the printer driver (especially if youre using a text printer that cant print graphics). The most likely explanation, however, is that you have confused borders and gridlines. In grade school you probably learned that the equator is an imaginary line around the center of the earth. Gridlines, like the equator, are imaginary lines, a visual representation of the table cell boundaries. They do not print. Display of table gridlines is toggled on and off by Table | Show/Hide Gridlines (in Word 2007, Table Tools | Layout | Table | View Gridlines). Gridlines are displayed in both Normal (Draft) and Print Layout views but not in Print Preview because they do not print. In Print Layout view, even if you have table gridlines hidden, you will see a dotted line representing cell boundaries if you have Text boundaries checked in Tools | Options | View (in Word 2007, Office Button | Word Options | Advanced: Show document content: Show text boundaries). If you want table borders that print, you will need to apply borders to the table or selected cells or sides of cells. For more on this, see Run for the border. Users often dont realize that Word uses tables to format labels. If you choose New Document on the Labels tab of the Tools | Envelopes and Labels dialog (Mailings | Create | Labels in Word 2007), the page you get will be a sheet of labels set up as a table. If you dont have table gridlines displayed, it will appear to be an entirely blank page. With gridlines displayed, you will see the label structure. If you also display nonprinting characters, you can see the end-of-cell markers (even without the gridlines), which give you another clue. If you want to be able to toggle table gridlines on and off easily, you may want to add a Gridlines
22
button to a toolbar or the QAT, as follows: Word 2003 and earlier: Go to Tools | Customize. On the Commands tab, select Table under Categories and Gridlines under Commands. Drag the button to a toolbar (next to Insert Table on the Standard toolbar is a logical place). Since the button is a toggle, it has (as on the Table menu) two button faces and two ScreenTips:
Word 2007: Right-click on the View Gridlines button on the Ribbon and choose Add to Quick Access Toolbar. This button will also be a toggle with the same button face as above.
23
Barnhill
Applies to Word 2004 and earlier. You can create a wide variety of special effects in Word using paragraph and table borders. Use of borders, however, is often misunderstood. This article will attempt to clear up some misunderstandings and provide useful tips for using borders effectively.
Access to borders
There are (at least) three ways to apply or remove borders in Word: the Format | Borders and Shading dialog, the Tables and Borders toolbar, and the Borders button on the Formatting toolbar. They offer varying levels of customization.
24
Level 1: Borders and Shading dialog The Format | Borders and Shading dialog gives you the most control over borders and also gives you access to Page Borders (Word 97 and above) and shading. Using the Setting buttons, you can choose from among several preset borders. Borders can be applied to tables, table cells, text paragraphs, and selected text, and the preset borders offered vary according to the context. For text paragraphs, for example, Word offers the Shadow and 3-D options, which should automatically apply a combination of borders to create a shadowed or 3-D effect. Actually, although Shadow will work with any border or line weight (and the only way to get a deeper shadow is to choose a heavier line), 3-D doesnt work at all unless you choose one of the line styles that combine lighter and heavier lines. It merely reverses the inside and outside lines to create the 3-D effect. If you are working in a table, the presets include the All and Grid options. All applies the same border to all cell boundaries, both outside and inside. (This is the default format when you insert a table.) Grid appears to do the same thing (although it actually changes the inner border to pt!) until you choose a different line weight or style; Word then applies that to just the outside boundaries, giving you a heavier line around the entire table and, by default, a pt rule for the inside boundaries. Using this setting, the only way to get heavier Inside lines or lighter ones than pt is to format them manually in the Preview. After selecting Grid and applying your thick outer border; but without closing the dialog, click on one of the inner lines in the preview pane before you change the width setting (otherwise you will just end up changing the weight of the outer border again!). Now change the Width setting to whatever weight you want the inner border lines to have; and click both the horizontal and vertical inner lines in the Preview. Then click OK. A good general rule to remember when changing the weights of lines in the Preview pane is that you must always select the line you want to adjust before you change the Width setting; which is downright unintuitive, but once you know the rule, it's simple enough to apply.
25
Another option is Custom, which allows you to select different line weights and styles for various sides of a cell or paragraph. Actually, you dont have to choose this option; it will be chosen for you if you change a given border from the set Box, All, Grid, Shadow, or 3-D settings. It is not immediately obvious how to do this, though. You must first select the line weight, style, and color, then click on the appropriate line (or corresponding button) on the Preview at the right side of the dialog (if you click these lines or buttons before selecting a line, you will either apply the default style or, if it is already applied, remove it). If you are applying a border to text paragraphs, you will not have the Inside option unless you have more than one paragraph of text selected. This is more difficult to explain than to figure out; with a little experimentation, you will see how the preview works. If you are formatting entire text paragraphs, the Options button will be enabled. The Options tab allows you to set (from 1 to 31 points) how far the border should be from text. The defaults are 1 point top and bottom and 4 points left and right. The distance options are available only for the sides of the paragraph where you have a border. If you want a top border, for example, to extend beyond text right and left, changing the Left and Right options will have no effect; the border will be exactly the same width as your paragraph. You can get around this by applying a white (nonprinting) border on the sides and then setting the distance as needed. In tables the Options tab is unavailable. To increase the distance from text, you must use paragraph indents (left and right) or Spacing Before/After (top and bottom) in Word 97 and earlier or adjust the cell padding in Word 2000 and above. In text paragraphs, Spacing Before/After is added above or below the border; if you want additional space before and/or after a table, you will have to add Spacing After to the paragraph above and/or Spacing Before to the paragraph below. If you are trying to border selected text (less than an entire paragraph), the dialog appears to allow you to choose which sides of the text to border, but in fact the only available options are those that create a box (Box, Shadow, and 3-D), and you cannot adjust the distance from text. If you want to put a border on one or more (but not all) sides of selected text, investigate the EQ field in Words Help; the \x switch for this field, together with switches that indicate top, bottom, left, and right,
26
By default there is a button on the Standard toolbar (next to Insert Table) to toggle display of the Tables and Borders toolbar. Although this toolbar is by default floating, you can, if desired, dock it at the top or bottom of your screen to get it out of the way. (Docking it at the side is not recommended; if you do that, the dropdown list boxes become buttons that bring up the Borders and Shading dialog.) With this toolbar you can accomplish many of the same things you can do in the Borders and Shading dialog, although for most purposes, the Borders and Shading dialog works better. You can choose a line style, weight, and color and, using the Borders palette, apply borders to an entire table (or paragraph) or selected cells. (You dont have access to the Options tab, but this is unavailable in tables, anyway.) The Borders palette has ten buttons you can use to apply Inside, Outside, Top, Bottom, Left, or Right borders or a grid (All) or to remove borders entirely (No Border). You can also remove borders selectively by clicking on buttons to turn them off. The border applied by the buttons on the Borders palette defaults to the most recently selected style, weight, and color, which is displayed on the toolbar. If you will be applying many borders of the same weight to selected sides of selected table cells, you may find it more convenient to display the Borders palette alone. Click the down arrow on the Borders button and release the mouse button. As you pass the mouse over the top of the palette, you will see a tiny title bar become active, and a ScreenTip says, Drag to make this menu float. Click on the title bar and drag the palette off the toolbar. You can then close the Tables and Borders toolbar, leaving the Borders palette floating. This little toolbar doesnt really get in the way, but you can dock it on any side of your screen if desired.
Incidentally, the Borders palette in Word 2000 and above, as shown in these screen captures, contains three buttons that are not present on the Word 97 one, all three being almost completely useless! The two diagonal buttons create diagonal lines that intersect your text like this:
They do not actually split your cell diagonally; they just create the appearance of doing so. If you want to further this deception, you will need to format text accordingly:
The Horizontal line button inserts a web-based horizontal line (i.e. an <hr> tag) like this:
27
... which is similar to applying a paragraph border but far less flexible (for instance, you have no control over its color, its thickness, or its distance from the text). There is never likely to be an occasion when you would want to use any of the new buttons! One thing the toolbar is good for is applying fills; in Word 97 and above, when you apply a fill using the Borders and Shading dialog, it often changes your borders in unexpected ways. Unfortunately, there are also some disadvantages to using the Tables and Borders toolbar. Level 3: Borders button on the Formatting toolbar The Borders button on the Formatting toolbar opens the same palette as the one on the Tables and Borders toolbar. You dont get the option of selecting line style, weight, and color (it merely applies the currently selected default), but you can tear off this palette to make a floating toolbar the same way you can the one on the Tables and Borders toolbar. For quick formatting, and especially for removing borders, this is definitely the quickest method.
Some gotchas
Conversely, if consecutive paragraphs have the same formatting and have the same border style applied, they will all be in the same box. You can apply an Inside border to separate the paragraphs, but if you want them to be actually in separate boxes, there are two ways to accomplish this: 1. Insert an unbordered paragraph between them. Format the line spacing of the paragraph to be Exactly the distance you want between the boxes. This assumes that the two paragraphs do not have any Spacing Before or After 2. If your paragraphs have Spacing Before or After and you want to preserve this distance between the boxes, you can use a more devious method: take advantage of the first gotcha and make the paragraphs different. Give one of them an infinitesimal indent. If you press Alt while dragging the left or right margin marker on the ruler, you can move it as little as 0.01". You may find that you sometimes get borders when you dont want them. If you have not cleared the check box for automatic borders on the AutoFormat As You Type tab of Tools | AutoCorrect, these may appear as unexpectedly (and as welcome) as the Spanish Inquisition. For more on this, see There is a line in my document that I can't delete. If you are coming to Word from WordPerfect, you may be accustomed to seeing a distinct difference between a bottom border on one cell and a top border on the one below. Perhaps you've even combined these to get a double or heavier border. But you may also have found that this arrangement often made it very difficult to align intersecting borders properly. Word works differently: a bottom border on one cell is in exactly the same location as a top border on the cell below. This is normally a good thing, but every now and then Word, in its infinite wisdom, will decide that the border you applied as a bottom border is actually at least in part a top border on the cell below, making it impossible to remove it by turning off the Bottom Border button on the
28
Borders palette. At such times you must just shrug and move on to the cell below and remove the top border. Tables continued from one page to another often lose the bottom border of the last row; sometimes you can restore it by explicitly applying a bottom border to that row (not just borders between rows). Word has a way of perversely interpreting a border between rows as being the top of one row or the bottom of another, but not both.
Drawing tables
If you draw a table using the pencil tool on the Tables and Borders toolbar, the cells are given the default pt black rule border unless you have selected a different line style, weight, and/or color on the toolbar dropdown before drawing the table. You can change the borders using the tools on the toolbar. You can also remove all or some of the borders by selecting cells and clicking the appropriate buttons on the Borders palette. It may be tempting to use the Eraser tool to erase borders, but this often doesnt work; what frequently happens is that you instead erase the cell boundary, thereby merging two adjacent cells, which may not be at all what you intended. The Eraser tool does have one real use though. It provides by far the quickest way of merging two columns. But even for that it is flawed you can only merge one page's worth at a time! I personally dont recommend drawing tables. I have yet to find a table that could not be effectively created using Insert Table and then adjusting cell widths and merging or splitting as necessary. And I have seen (and corrected) some horrible messes made by inexpert users using Draw Table (actually, even for expert users, it is very difficult to avoid making a mess of your tables if you use this tool). If you do use the table drawing tools, be sure to display cell gridlines and/or text boundaries so you will know if you have inadvertently erased a cell boundary when you meant to erase a border; better yet, dont use the eraser for anything except erasing cell boundaries.
29
30
31
When you open a new blank document in Word, you begin typing at the left side of the screen/page and continue typing to the right margin, where Word wraps your text back to the left so you can start again. All your lines of text are full width. But sometimes you need to divide your text into two or more columns.
Tabs
If you want to enter text in one column, then text in another column on the same line, then more text in the first column (but on the next line), and so on, and if each of the entries will fit on one line, you may be able to align the columns using tabs. What you're doing here is creating a tabbed table: Just be sure you set a specific tab stop for each column location; don't use Word's built-in tabs.
Tables
If you want to be able to enter some text in one column, then text in another column aligned with it, then text in the first column again, then the second (and possibly a third, fourth, or more), and if the text in each column must be able to wrap to the next line, then what you want is a table. A table allows you to align text vertically as well as horizontally. Whenever you need to synch the columns, you begin a new row. Table columns are especially good for things like opera scores, where you need the text in the original score and the translation to line up with each other vertically.
32
second textbox. The idea of Text Box columns is that, unlike snaking columns (which are covered in detail below), they can be used to cater for articles which start on page 1 of a publication and continue in the middle of page 14. An example is to be found in the (appallingly formatted!) Newsletter Wizard that is supplied with some versions of Microsoft Office (Word 2007 has no wizards, but there are plenty of equally appalling templates in the Template Gallery at Microsoft Office Online). However, Text Box columns don't work well and are best avoided. If you need the ability to flow text between non-consecutive pages, you will save yourself a lot of heartache by using a DTP package such as MS Publisher or Adobe PageMaker. For most purposes, however, snaking columns work admirably.
Snaking columns
If you want the text to fill the first column and then snake into the next and fill it, continuing from Column A to Column B, then Column A on the next page, then you want newspaper-style columns, the subject of this article. (Note that this type of columns is not appropriate for text to be aligned vertically across the page; for that you need to use a table). If you can make any sense of the above passage, you should have no trouble learning to work with columns!
Parallel columns
If you are coming to Word from WordPerfect, you may be used to having another option: parallel columns. Word doesn't offer this option, but you can achieve the same effect using a one-row table with the required number of columns. Be aware, though, that Word can be uncomfortable with very long single-row tables, which may lead to document corruption. Usually you will want to start a new row occasionally, anyway, to line up text in the two (or more) columns.
Getting started
Sometimes you will want just one portion of your document to have multiple columns. We'll discuss later how to accomplish that. For now, however, let's assume that your entire document will be multicolumn. For illustration purposes, let's say that it is a four-panel brochure on legalsized paper in landscape orientation.
33
Word 2003 and earlier: After setting your document margins in File | Page Setup, click on the Columns button on the Standard toolbar, drag to select four columns, and release. Your document will now be divided into four columns. You can also use Format | Columns to access the Columns dialog. Word 2007: After setting your document margins through Page Layout | Page Setup | Margins or in the Page Setup dialog (accessed via the dialog launcher arrow in the bottom right corner of the Page Setup group), click Columns in the Page Setup group and choose More Columns This opens the Columns dialog (see figure below), where you can choose the number of columns.
Note: If you don't have text boundaries displayed, you can select this option as follows: In Word 2003 and earlier, check the box for Text boundaries on the View tab of Tools | Options. In Word 2007, this option is at Office Button | Word Options | Advanced | Show document content: Show text boundaries.
You will also see a change in the horizontal ruler. If you are working in Normal (Draft) view, the only change you will see will be in the ruler, but when you type you will find that your line now wraps at a shorter length. For this reason, make sure that you don't have very large paragraph indents. If one of your styles, for example, has a one-inch indent both left and right (the default formatting for the Block Text style), there won't be much left of it in a column less than three inches wide!
34
a column break with Ctrl+Shift+Enter. This will take you to the top of the next column. Note that column breaks, like page breaks, inherit their formatting from the following paragraph; this can sometimes be a problem. Also, sometimes you will eventually fill the first column so full that there is no need and indeed no room for a column break; in that case you may have to delete it. A column break in a filled column can be difficult to see in Page Layout (Print Layout) view, however, so you may need to switch to Normal (Draft) view to select and delete it.
Note: If you need to insert a break manually, do it as follows: In Word 2003 and earlier, use Insert | Break and choose Continuous under Section break types in the Break dialog. In Word 2007, this dialog is available (as a gallery) via Page Layout | Page Setup | Breaks.
Whenever you have a multicolumn section in the middle of a page, Word will automatically balance the columns for you. If you want the columns to break differently (that is, unevenly), you can either insert a column break (Ctrl+Shift+Enter) or control text flow using the Keep with next and/or Keep lines together paragraph properties. If a multicolumn section ends a page (because you have inserted a Next Page section break or a page break or formatted the next paragraph as Page break before or used Keep with next to force text to a new page), columns will not be balanced unless you insert a Continuous section break in addition to whatever other break you have used.
Footnotes
Another limitation of columns is that they don't play well with footnotes. Footnotes in a multicolumn document will be wrapped to the column width. Moreover, if the footnote occurs in a multicolumn section in a single-column document, that section will insist on being on a page by itself even though you have used Continuous section breaks before and after it. The workaround for this is so clumsy that you may well decide it is not worth it, but if you must combine footnotes with columns and insist on full-width footnotes (and especially if the
35
multicolumn section is part of a primarily single-column document), here's how to solve the problem:
1. 1. Insert the footnote in a single-column section as close as possible to the desired location of the actual footnote reference mark (so that the footnote will be on the same page and in the correct order). 2. 2. Where you want the footnote reference mark, insert a cross-reference to the number of the footnote you just inserted. In Word 2003 and earlier, do this with Insert | Reference | Cross-reference | Reference type: Footnote; Insert reference to: Footnote number (formatted). In Word 2007, the Cross-reference dialog is accessed via References | Captions | Cross-reference or Insert | Links | Crossreference. 3. 3. Select the actual footnote reference mark (in the single-column text) and format it as Hidden (Ctrl+Shift+H).
36
Tools Format tab; in the Text Box Styles group, click Shape Outline and choose No Outline. If you use a frame, it doesn't seem to matter whether you set wrapping to None or Around. For a text box, the default wrapping style in many versions is None of In Front of Text, which will not work (nor will Through). Any other wrapping style seems to be satisfactory. You will need to experiment with the other layout options to find which ones work best for your situation. You may want to wait till you're fairly far along in entering text before you insert a text box or frame because the effect of doing this is to reduce the text boundaries to the amount of text you have entered (instead of showing the four rectangles you saw when you first created the columns). This can be rather disconcerting.
Summary
Avoid text box columns. Use snaking columns when you need text to flow from one column to another, and table or tab columns when you don't. Table columns are especially good for things like opera librettos, where you need the text in the original score and the translation to line up with each other vertically.
37
Barnhill
It's best to avoid manual page breaks in documents wherever possible, and luckily this is usually easy to do with paragraph formatting: In Word 2003 and earlier, use Format | Paragraph (or Paragraph on the shortcut menu) to open the Paragraph dialog. Select the Line and Page Breaks tab. In Word 2007, on the Home tab, locate the Paragraph group. Click the dialog launcher (small arrow) in the bottom right corner to open the Paragraph dialog. Select the Line and Page Breaks tab. On the Line and Page Breaks tab of the Paragraph dialog are several options that control text flow: Widow/Orphan control prevents a single line of a paragraph from being left alone at the top or bottom of a page. This property is enabled by default for all styles in Word. Keep lines together, as the name implies, keeps all the lines of a paragraph together. That is, it keeps a single paragraph from being split across two pages. Keep with next keeps a given paragraph with the following one. That is, it prevents the two paragraphs from being separated across two pages (the individual paragraphs, however, can be split internally unless Keep lines together is also applied). This property is assigned by default to Word's built-in Heading 1Heading 4 styles to ensure that headings stay with following text. Page break before causes a page break before the paragraph. Unlike a manual page break inserted using Ctrl+Enter, however, it is not represented visually in the document and does not inherit the properties of the following paragraph. By judicious application of the first three properties, you can usually maneuver Word into putting a page break where you want it without having to insert a manual page break or use Page break before.
38
Note: Whenever you have Keep with next, Keep lines together, Page break before, or Suppress line numbering enabled for a given paragraph, you will see a small black square bullet in the left margin. If you double-click on this bullet, you will open the Paragraph dialog with the Line and Page Breaks tab displayed. For an easier way to apply these properties to paragraphs, you can (in Word 2003 and earlier) add toolbar buttons for them. Unfortunately, these buttons by default have no button icon. For an add-in that contains these buttons with attractive icons, see Custom Toolbar Buttons.
Things work a little differently in tables, however. In a table, the Keep lines together and Widow/Orphan control properties have no effect at all. To keep a table together on one page, you must perform two actions: 1. Prevent rows from breaking internally.
In Word 97 and earlier, open the Table | Cell Height and Width dialog and select the Row tab. Clear the check box for Allow row to break across pages. In Word 2000, 2002, and 2003, open the Table | Table Properties dialog and select the Row tab. Clear the check box for Allow row to break across pages. In Word 2007, on the Table Tools | Layout tab of the Ribbon, locate the Table group and click Properties. In the Table Properties dialog, select the Row tab. Clear the check box for Allow row to break across pages. Note: The choice of whether rows are allowed to break is strictly an either/or proposition. If you do allow a row to break, it can break anywhere; as mentioned, Widow/Orphan control and Keep lines together are ignored, so the only way to force a table to break only between paragraphs is to make sure each paragraph is in a separate row.
2. Keep rows together. Select the entire row and enable the Keep with next property. Do this for every row of the table except the last.
Although it is not relevant to a one-page table, note that Page break before, when applied to a table row, does not split a table as a manual page break (inserted with Ctrl+Enter) does. This means that repeating heading rows will continue to be repeated and the table can continue to be treated as a single table. For information on controlling page breaks in tables longer than a page, see How do I control where the page breaks will fall in a table that extends over several pages?
39
40
Rado
1. 2.
As a user In code
To return to top, press Ctrl+Home, or use Alt + Left Arrow to Go Back)
As a user
1. Working in Normal view when you can helps, especially if you turn off Background repagination (Tools + Options + General). Whatever you do, though, tables in Word 2000 and higher are a lot slower in most respects than in Word 97 an unfortunate by-product of the new table engine created so that Word tables could be fully HTML-compatible. 2. If using Word 2000 and above, select Table | Table Properties | Options, and turn off the checkbox: Automatically resize to fit contents. As well as slowing tables down considerably, this setting gives (usually) undesirable results, but unfortunately is automatically switched on in all new tables. 3. Don't create a single row containing a large amount of text. I have seen many tables containing rows which (with non-printing characters displayed) look something like this:
Figure 1: A badly laid out table row (shown with non-printing characters
41
Apart from anything else, laying out table text as shown above makes it a complete nightmare to get everything to line up, which defeats the object of using a table in the first place, the great strength of tables being that they line text up automatically if used properly. But in addition, rows containing many paragraphs slow tables down. So create a separate row for each logical element of the table, as shown in Figure 2. Note that if you don't want horizontal borders between some of the rows, you don't have to have them; so not wanting borders is not a reason to add paragraphs instead of adding rows:
Figure 2: How the row in Figure 1 should have been laid out as six separate rows, but with no horizontal border between the rows
4. Break long tables up (use several smaller tables rather than one very long one), separating the sub-tables with headings. So rather than, for instance, creating something like this:
... split your tables up into logical sub-tables instead, putting your headings outside the tables (using Heading styles), like this:
42
5. Avoid using merged cells as much as possible: wherever you can get away with it, remove unwanted borders instead. 6. In Word 2000 and above, use text-wrapped tables only when really necessary. Set textwrapping to None whenever you can. For more on text-wrapped tables, see: Table basics. 7. In Word 2000 and above, if your tables contain graphics, make them inline where possible.
In code
1. If using Word 2000 and above, turn off Automatically resize to fit contents for all tables:
Selection.Tables(1).AllowAutoFit = False
Whatever you do, though, tables in Word 2000 and higher are a lot slower in most respects than in Word 97 an unfortunate by-product of the new table engine created so that Word tables could be fully HTML-compatible (but see 5. and 7. below for an astonishing exception to this rule). 2. 27 above apply to tables created with code as well. In the case of switching views and turning off background repagination, it is polite to the user to leave their settings as you found them, i.e.:
Dim ViewType As Long, PaginationSetting As Boolean ViewType = ActiveWindow.View.Type PaginationSetting = Options.Pagination 'rest of your code Options.Pagination = PaginationSetting ActiveWindow.View.Type = ViewType
Unfortunately, even with ScreenUpdating switched off, the screen flickers when you change views. The only way to prevent this is to use the the LockWindowUpdate API (which is beyond the scope of this article, but a Google search will turn up details on it). So it's only worth bothering to change views for large tables. 3. If you are putting data into a Word table using code (e.g. if you are reading it from a database), you will get much better performance if you initially put the data into the Word document as tab-delimited text, and then convert the text to a table at the very end. For example (the following code sample requires you to set a reference to DAO, and also assumes you have
43
the Northwind sample database installed it is one of the sample databases supplied with Office, so if it is not already installed on your system, you can re-run Setup in order to install it ):
Sub GetDataIntoTable() Dim db As Database, rs As Recordset, MyRange As Range, i As Integer Set db = OpenDatabase(Name:= _ "c:\program files\microsoft office\office\samples\northwind.mdb") Set rs = db.OpenRecordset(Name:="Shippers") Set MyRange = ActiveDocument.Content MyRange.Collapse wdCollapseEnd MyRange.InsertAfter Text:=rs.Fields(1).Name & vbTab & rs.Fields(2).Name & vbCr Set MyRange = ActiveDocument.Content MyRange.Collapse wdCollapseEnd For i = 0 To rs.RecordCount - 1 'Insert the data as tab-delimited text MyRange.InsertAfter Text:=rs.Fields(1).Value & vbTab & rs.Fields(2).Value & vbCr rs.MoveNext MyRange.Collapse Direction:=wdCollapseEnd Next i rs.Close db.Close 'Now convert to table MyRange.Start = ActiveDocument.Range.Start MyRange.ConvertToTable Set db = Nothing Set rs = Nothing End Sub
If some cells in your table need to contain more than one paragraph (or to contain manual line breaks), separate those paragraphs or lines, initially, with a dummy delimiter such as a comma or a dollar sign; and then do a Find and Replace at the end (after converting the text to a table), to replace the delimiter with a paragraph mark or manual line break, as desired. For a code sample that illustrates this technique, see: How to generate a table of samples of every font on your system. 4. If for some reason you can't insert your text in tab-delimited format and convert to table at the end, then don't build up your table as you go by adding a row at a time. Instead, work out in advance the total number of rows that you'll need (e.g. by reading all your values into an array before inserting any of them in the document) and then create the entire table in one go; e.g.:
Set oTable = ActiveDocument.Tables.Add(Range:=MyRange, _ Numrows:=1000, numcolumns:=4) 'Word 2000 only: oTable.AllowAutoFit = False
5. If inserting text, use ranges rather than selections (as illustrated in the above code sample): and also, use characters such as vbCr and vbTab to allow you insert as much text as possible with a single statement again, as illustrated in the above code sample. For instance:
MyRange.InsertAfter Text:=rs.Fields(1).Value & vbTab & rs.Fields(2).Value & vbCr
44
6. If inserting a large amount of text into the document, make sure background spelling and grammar checking are switched off. At the end of your macro, out of politeness to the user, switch the settings back on if they were on to start with. Also, if you know that the inserted text won't need to be spelling or grammar checked, you can mark the inserted range as already checked, without marking the rest of the document. (Thanks to Greg Chapman for this tip).
Dim SpellSetting As Boolean, GrammarSetting As Boolean, _ MyRange As Range SpellSetting = Options.CheckSpellingAsYouType GrammarSetting = Options.CheckGrammarAsYouType With Options .CheckSpellingAsYouType = False .CheckGrammarAsYouType = False End With 'Insert your text, e.g. Set MyRange = Selection.Range Selection.InsertFile "C:\Temp\Temp.doc" 'Or insert it from a database, whatever 'If you know that it's safe to do so, mark the inserted text as already checked, 'but don't mark the text that you didn't insert. If inserting from a database, 'set a range to the inserted text and operate on that range. 'If using Selection.InsertFile, use the following: MyRange.End = Selection.End With MyRange .SpellingChecked = True .GrammarChecked = True End With 'Rest of your code, and then at the very end: With Options .CheckSpellingAsYouType = SpellSetting .CheckGrammarAsYouType = GrammarSetting End With
7.
8. When cycling through table cells, never refer to a table cell by its coordinates; as that is horrendously slow, because it forces Word to calculate from scratch, for every single cell, where in the document the cell in question actually is. And don't move selection from cell to cell, as this will also slow your code down dramatically. Whilst it is much faster to cycle through the Cells collection, as in:
Sub OperateOnEveryCellUsingTableObject() Dim oCell As Cell For Each oCell In Selection.Tables(1).Range.Cells oCell.Range.Text = "Hi there" Next oCell
45
End Sub
... a much faster method still (with screen updating switched off) is to select the table, in code, and then cycle through the cells within the selection don't ask me why this should be faster, but it is:
Sub OperateOnEveryCellInSelectedTable() Dim oCell As Cell Application.ScreenUpdating = False Selection.Tables(1).Select For Each oCell In Selection.Cells oCell.Range.Text = "Hi there" Next oCell Application.GoBack Application.ScreenUpdating = True End Sub
When I timed the above macros in Word 97 and in Word 2000, using a 350-row, 5-column table, the results were very interesting (I've rounded the results to 1 decimal place): Word 97 OperateOnEveryCellUsingTableObject 38.5s 53.8s OperateOnEveryCellInSelectedTable 4.5s The above results were obtained with a table created in Word 97. If the table was created in Word 2000 (and if AllowAutoFit was switched off), then using the Table object became significantly faster in Word 2000 (though not in 97); but was still far slower than using a Selection object. If the document was created in Word 2000 and then saved in Word 97, the results were similar to the above. I have no theories to explain these results, but they are easy to reproduce. Tests by colleagues who have access to Word 2002 gave broadly similar results to Word 2000. Turning off screen updating made no difference to the speed of the OperateOnEveryCellUsingTableObject() macro, although it dramatically speeded up the OperateOnEveryCellInSelectedTable() macro. 9. When operating on specific rows, or comparing the contents of adjacent rows, use the Row object, as in the code samples at Deleting duplicate rows in a table. 10. If you want to operate on the cells in a specific table column, you can't cycle through the cells within the column's Range Ranges and Columns simply don't mix. Crazily, a table column's Range contains many cells that are not actually within the column. This must once have seemed like a good idea to someone at Microsoft, probably because they were suffering from a bad hangover at the time! There is a certain pedantic logic to it: a column's range contains all the cells starting from the top of the column, moving through the table from left to right along each row, until you get to the bottom of the column. From a usability perspective this was a nightmarish 5.3s Word 2000
46
design decision, though, and well worth emailing mswish@microsoft.com about. By far the fastest way of operating on a specific column is to select it and then cycle though the selected cells, as in:
Sub OperateOnSelectedColumn3() Dim oCell As Cell Application.ScreenUpdating = False 'Select the third cell in the first row of the table Selection.Tables(1).Cell(1, 3).Select 'Select column 3 Selection.SelectColumn 'Operate on the cells in column 3 For Each oCell In Selection.Cells oCell.Range.Text = "Hi there" Next oCell Application.GoBack Application.ScreenUpdating = True End Sub
Note that you cannot safely use the Columns object to specify which column you want to select, as in:
Selection.Tables(1).Columns(3).Select
.. because that gives an error message: Cannot access individual columns in this collection because the table has mixed cell widths, either if there are any merged cells, or even if any cell anywhere in the table has a slightly different width than the rest of the cells in the same column! So for all practical purposes, the Column object is completely useless another design decision resulting from far too many Tia Marias laced with vodka, and well worth an email to mswish@microsoft.com. If there might be merged cells in row 1 of the table, you could select the third cell in the last row of the table instead, and then select the column, rather than using the first row:
Dim oRow As Row, oCell As Cell Application.ScreenUpdating = False Set oRow = Selection.Tables(1).Rows.Last oRow.Cells(3).Select Selection.SelectColumn For Each oCell In Selection.Cells oCell.Range.Text = "Hi there" Next oCell Application.GoBack Application.ScreenUpdating = True
Instead of selecting the column you could cycle through every cell in the table, operating on those cells whose ColumnIndex property matches the column you want, as follows:
Sub OperateOnColumn3UsingRanges() Dim oCell As Cell For Each oCell In Selection.Tables(1).Range.Cells If oCell.ColumnIndex = 3 Then oCell.Range.Text = "Hi there" End If Next oCell
47
End Sub
... but this is not only much slower than selecting the column, but also, if there are any horizontally merged cells in the table, the ColumnIndex property gives undesirable results. When I timed the above macros in Word 97 and in Word 2000, using a 350-row, 5-column table, the results on my machine were as follows (I've rounded the results to 1 decimal place): Word 97 OperateOnColumn3UsingRanges 10.7s OperateOnSelectedColumn3 1.1s The above results were obtained with a table created in Word 97. If the table was created in Word 2000 (and if AllowAutoFit was switched off), then the OperateOnColumn3UsingRanges macro became significantly faster in Word 2000 (though not in 97); but was still far slower than using a Selection object. If the document was created in Word 2000 but then saved in Word 97, the results were similar to the above. As with 7. above, I have no theories to explain these results, but they are easy to reproduce. Tests by colleagues who have access to Word 2002 gave broadly similar results to Word 2000; and again, turning off screen updating made no difference to the speed of the OperateOnColumn3UsingRanges() macro, although it dramatically speeded up the OperateOnSelectedColumn3() macro. If formatting the borders and shading of a table, it is far more efficient, and can speed 11. up your code dramatically (even in Word 97), if you execute the built-in FormatBordersAndShading dialog (without displaying it), than it is to use native VBA Methods to do the formatting. This trick also greatly reduces the risk of getting Formatting too complex error messages. In essence, this is because you can execute many commands simultaneously using the dialog, whereas, using VBA methods, you have to execute one statement at a time, and wait for one to finish before the next can start. For a more detailed discussion of the principles behind this, and for some code samples to get you started, see #2 at Getting help with calling Word's built-in dialogs using VBA (and why doing so can be much more useful than you'd think), in the section: Why use built-in dialogs?. 12. If doing a great deal of formatting of tables, then even all of the above tricks combined may not prevent you from getting the odd Formatting too complex error message. Periodically clearing the Undo buffer can help prevent this:
ActiveDocument.UndoClear.
Word 2000
7.3s
0.7s
Make sure you have turned screen updating off. If that isn't sufficient, the LockWindowUpdate API (which is beyond the scope of this article, but a Google search will turn up details on it) is more efficient still, as is making the application invisible.
48
If you still get Formatting too complex error messages, try saving the document periodically; or as a last resort (in really huge tables), periodically save the document, close it and open it again. If you use all these tricks, you will find that the performance of tables is not an issue, even in Word 2000 and higher.
49
How can I resize a table to fit the page's width? Word 2000
In Word 2000 you can select Table + Properties, click on the preferred width checkbox; where it says Measure in, change it to percent, and in the width spinbox, type 100%. The relative column widths are preserved in the resized table. Or if you want to do it programmatically, you can use:
Selection.Tables(1).PreferredWidthType = wdPreferredWidthPercent Selection.Tables(1).PreferredWidth = 100
Word 97
In Word 97, you can select the entire table, and on the Column tab of Table | Cell Height and Width, type "a" and press the down arrow. The box will fill with the word Auto; OK out, and the table is resized to the margin width. Unfortunately (unlike Word 2000), the columns in the resized table are all equal widths. Alternatively, if you click in any cell (with nothing selected) and follow the same procedure, the column which the insertion point is in will be resized so that the table fits the page margins without the other column widths being affected. If you want to preserve the relative column widths when you resize the table, (as one generally does), you'll need a macro to do the job: Sub MakeTableFitPageSize() Dim myTable As Table Dim OriginalRange As Range Dim oRow As Row Dim oCell As Cell Dim UsableWidth As Single Dim TableWidth As Single Dim CellNo As Long If Selection.Tables.Count = 0 Then
50
MsgBox "Please put your cursor inside a table and try again", vbInformation Exit Sub End If Application.ScreenUpdating = False System.Cursor = wdCursorWait Set OriginalRange = Selection.Range Set myTable = Selection.Tables(1) myTable.Rows.SetLeftIndent _ LeftIndent:=0, RulerStyle:=wdAdjustNone 'Calculate usable width of page With ActiveDocument.PageSetup UsableWidth = .PageWidth - .LeftMargin - .RightMargin End With 'Calculate width of top row, on assumption this will be 'the same as table width On Error Resume Next For CellNo = 1 To myTable.Rows(1).Cells.Count If Err = 5991 Then MsgBox "This macro doesn't work with tables that have vertically merged cells", _ vbInformation GoTo CleanUp Else If Err Then MsgBox Err.Description, vbInformation GoTo CleanUp End If TableWidth = TableWidth + myTable.Rows(1).Cells(CellNo).Width Next CellNo On Error Goto 0 'Calculate and assign width of each cell in each row, such that the cell width relative 'to the table's width stays the same as before. Do it for each row individually rather than 'for a column at a time- otherwise the macro won't work 'if any of the rows contain horizontally merged cells For Each oRow In myTable.Rows For Each oCell In oRow.Cells oCell.Width = (oCell.Width) * (UsableWidth / TableWidth) Next oCell Next oRow OriginalRange.Select Cleanup:
51
'Clear variables from memory Set myTable = Nothing Set OriginalRange = Nothing Set oRow = Nothing Set oCell = Nothing UsableWidth = 0 TableWidth = 0 CellNo = 0 System.Cursor = wdCursorNormal Application.ScreenUpdating = True
End Sub
52
Rado
Word 97 Click anywhere in the table, and on the Table menu select Cell Height and Width. (Why Cell Height and Width, you may ask? Good question. Word 2000 is more logical). Where it says Indent from Left, make sure it's set to 0. Where it says Alignment, set it to Left, Centre, or Right as desired. Word 2000 Click anywhere in the table, and on the Table menu select Table Properties. Where it says Indent from Left, make sure it's set to 0. Where it says Alignment, set it to Left, Centre, or Right as desired. Using VBA In both versions of Word, the VBA for this is: With Selection.Tables(1).Rows .LeftIndent = 0 .Alignment = wdAlignRowCenter 'or set whichever alignment you want End With
53
54
Printer-friendly version: How to fix the Word 2000+ Cell Alignment buttons
Article contributed by Dave
Rado
In Word 2000+, both on the Tables and Borders toolbar, and on the shortcut menu that you see when you right-click a table-cell, the Cell Alignment buttons are almost unusable, if you want to use Word properly. In Word 97, there were three Cell Alignment buttons: Align Top, Center Vertically and Align Bottom.
Unfortunately, out of the box, Word 2000+ provides the buttons shown on the right, instead. These work by applying manual paragraph formatting to your text, in order to apply the horizontal alignment you select (this is especially annoying if your text is justified). Fortunately you can
replace the Word 2000 buttons with the Word 97 ones: 1. 2. Select Tools + Customize. Drag the Word 2000+ Cell Alignment menu button off the Tables and Borders toolbar.
3. On the Commands tab of the Customize dialog, select Table in the left pane, and drag the Align Top, Center Vertically and Align Bottom buttons from the right pane onto the Tables and Borders toolbar. Close the Tables and Borders toolbar. 4. On the Toolbars tab of the Customize dialog, scroll down the list of toolbars, and click on Shortcut menus. The Shortcut Menus toolbar will appear. 5. Pull down the Tables menu on the Shortcut Menus toolbar; select the Table Cell submenu, and drag off the Word 2000+ Cell Alignment button. 6. Select the Commands tab of the Customize dialog, select New Menu in the left pane,
55
then select the New Menu button in the right pane and drag it onto the Shortcut Menus toolbar, under the Table Cell submenu, to the position where the Cell Alignment button was before you dragged it off.
7. Right-click on your new button, and where it says Name, overtype the words New menu changing it to say Cell Alignment. 8. On the Commands tab of the Customize dialog, select Table in the left pane, and drag the Align Top, Center Vertically and Align Bottom buttons from the right pane onto your new Cell Alignment button.
9. With the Ctrl key held down, drag to copy the new Cell Alignment menu button from the Table Cell shortcut menu onto the Table Text, Tables and Whole Tables shortcut menus. 10. Drag the Word 2000 Cell Alignment menu button off the Table Text, Tables and Whole Tables shortcut menus. 11. Holding the Shift key down, select File + Save All, and save the changes to your Normal
56
template. Note: An even safer plan is to create an add-in first and make the customisation in your add-in, rather than in Normal.dot. That way, if you ever have to delete Normal.dot, you will not lose your customisation. For more on this see: What do Templates and Add-ins store?
57
Is there a way to add custom table formats to the Table Autoformat list?
Article contributed by Dave
Rado
In Word 2002, you can use (the somewhat ironically named) Table Styles. Unfortunately, if you do so, they do not apply paragraph styles to the text within your tables; they apply manual formatting instead which defeats the object of using styles. I would therefore not use this feature in documents of any importance. The simplest method of applying your own table formats when creating new tables is to create AutoText entries for each of your frequently used formats (Titles in top row, Left column, Both, etc.). And this is the only solution if you don't want to write macros. But that won't help you to format pre-existing tables (so won't help when pasting other people's tables into your documents). There is no solution to this that doesn't involve writing macros. The simplest way of addressing this in Word 2002 may be to define Table Styles via the user interface (may be, because the dialog may or may not allow you to define the format you want); then write a macro that offers the user a list of your corporate table styles to choose from, applies the one they chose, and then formats the text in the table using the appropriate paragraph styles. If you call your macro TableAutoFormat, it will intercept the built-in command, so that when the user selects Table + Table AutoFormat, your macro will automatically run. In Word 97 and 2000, if (and its a massive if) your company's standard table formats closely resemble one of the built-in ones, you can use a similar approach, with the addition of whatever code is needed to tweak the built-in format so that it conforms with your standard format. But most companies' table formats that I come across don't bear any resemblance to the Microsoft ones, so for most companies, the only really satisfactory way of addressing this is to write your own TableAutoFormat macro from scratch (again, call your macro TableAutoFormat, so that it intercepts the built-in command), and install it as an add-in. You will need to use all the tricks covered in: Maximising the performance of Word tables, in order to ensure that your code runs quickly. Also, keep your user dialog as simple as possible for instance, this is an example of one I've created in the past:
58
As an aside, Romke Soldaat's article Table Styles is sometimes linked to from the newsgroups when this question is asked; but in fact that article does not cover how to create your own table formats; instead, it covers how to assign meaningful names to Microsoft's built-in table formats.
I tried to use the { =SUM(ABOVE) } formula in a table but the answer was obviously incorrect
Article contributed by Suzanne Barnhill
If you have numbers in a table column and use the Table | Formula command in Word 2003 or earlier (Table Tools | Layout | Data | Formula in Word 2007), Word by default inserts the { =SUM(ABOVE) } formula field. This is quite often what you want: to sum the numbers in the column above the current cell. But often the result is obviously erroneous. There are two possible reasons for this:
59
1. If you are using Word 97 or earlier, the { =SUM(ABOVE) } field does not work for more than 85 rows. (This is not a problem with { =SUM(LEFT) } because the number of columns is limited to 63 anyway.) 2. A much more common problem, in all Word versions, is that Word stops counting when it gets to an empty cell or one with text in it instead of a number. To get around either of these problems, however, you can use the { =SUM( ) } field with cell addresses. For example, to add the numeric contents of the cells in column D (let's say there are 90 rows; the first one is a Heading Row, and #90 is the one where you want to put the answer), disregarding empty and nonnumeric cells, you can use the formula { =SUM(D2:D89) }. But what if you don't know how many rows you have? Unlike WordPerfect, Word does not display cell references in the status bar. Despite many requests for this feature, it will likely never be provided: Words developers tell us that merged cells and nested tables make the calculation so processor-intensive that constantly updating the status bar would adversely affect Words performance. There is, however, a way to get the address of a specific cell upon request. To help Word 97 users, Microsoft provided the TableCellHelper macro in the Macros8.dot template in the Macros folder of C:\Program Files\Microsoft Office\Office\. Although some subsequent Word versions have included templates containing macros, none of these has contained this macro. You can, however, download the Macros8.dot template by following this link. This macro still works in all versions, including Word 2007. When you run this macro, a message box reports the address of the cell you're in and the total number of rows and columns in the table. The easiest way to make this macro available in every document you create is to copy it into the Normal template, as follows: Word 2003 and earlier: With the Macros8.dot template open, go to the Tools | Templates and Add-ins dialog, click Organizer and select the Macro Project Items tab. You'll see two boxes labeled Macro projects available in. The one on the right will say Normal.dot (global template). The one on the left will say Macros8.dot (Template). When you select the TableCellHelper macro in the list on the left, the Copy button arrow will point right, and the labels above the boxes will say In Macros8.dot and To Normal.dot. Click the Copy button, and you will have added the TableCellHelper macro to the Normal template. There is another macro called TableCellHelper.AddToStd which, when run, will place a TableCellHelper button on the Standard toolbar. Since this button, as inserted, is entirely blank, so you can't even see where it went, I don't recommend copying this macro. Word 2007: On the View tab, locate the Macros group, click on the Macros button, and choose View Macros. Click on Organizer This opens an Organizer dialog similar to the one in Word 2003 and earlier; from here you can follow the instructions (above) for those versions. As an alternative to copying the macro to your Normal template, you could create a new template and store it in Word's Startup directory (as defined in Tools | Options | File
60
Locations). Storing it there makes it an add-in (or global template). You can then copy the macros to your add-in. If you need to use the TableCellHelper macro very often, you'll want some easier way to do it than by opening the Macros dialog, selecting TableCellHelper, and clicking Run. So you may want to add it to the Table menu or a toolbar in Word 2003 or earlier or to the QAT in Word 2007. Do this as follows: Word 2003 and earlier: Open Tools | Customize. On the Commands tab, scroll down the list of Categories till you see Macros. Find the TableCellHelper macro (if you copied the TableCellHelper.AddtoStd macro, be careful not to select this one). Select the TableCellHelper macro item and drag it to the menu bar, hovering over the Table menu item. When the Table menu opens, drop the macro in the desired location on the menu. If you prefer to have a toolbar button for this macro, drag it to a toolbar instead. Note: When you add a macro to a menu or toolbar, by default it will display the long string of text that is displayed in the Customize dialog (and no icon). This is rarely what you want. For a menu item, you can modify the text to be anything you like. To do this, right-click on the menu item and change the text in the Name box. For a toolbar button, you will probably want an icon instead; right-click on the button, choose Change Button Image, and select one of the icons offered (I used the big yellow question mark). Then right-click again and choose Default Style. Note that the default style for a toolbar button is an image only; for a menu item it is an image and text. The menu of actions you can use to modify a menu item or toolbar button (which can also be accessed by selecting the menu item or toolbar button and clicking Modify Selection in the Customize dialog) also includes Copy Button Image (to copy the icon from another button), Paste Button Image (to paste it on your new button), and Edit Button Image, which allows you to create your own custom button icon. (For more on adding buttons to menus and toolbars, see How to assign a Word command or macro to a toolbar or menu. For a library of button images, see Assigning custom button faces to your toolbar and menu buttons. Word 2007: Right-click on the QAT choose Customize Quick Access Toolbar In the Word Options | Customize dialog, choose Macros under Choose commands from: and select the TableCellHelper macro. Click Add>> to add it to the QAT. While it is still selected, click Modify and choose a button image for the new button (good luck with finding an appropriate one!). Word MVP Greg Maxey offers an improved version of the TableCellHelper macro at his Web site. For another workaround, see the following article: How to get a formula field to total an entire table column, even if some cells in the column contain text or are blank.
61
How to get a formula field to total an entire table column, even if some cells in the column contain text or are blank
Article contributed by Dave
Rado
The big problem with using the { =SUM(ABOVE) } field in Word (by selecting Table + Formula) to sum a table column, is that if there are any blank cells in the column, or any cells containing text, the formula only sums the cells below the first non-numeric cell it encounters. Another problem is that it can only total a maximum of 85 cells. One workaround is to specify the row and column numbers in the formula; for example, to sum rows 1-20 of the fourth column (column D), you could use { =SUM(D1:D20) }. The big problem with that, though, is that such a formula would need to be amended the moment you added or deleted any rows (and most users wouldn't remember to amend it). And unfortunately, if you used { =SUM(D:D) } to total column D, you'd get a circular reference (the formula would include itself in the total). However, see: I tried to use the { =SUM(ABOVE) } formula in a table but the answer was obviously incorrect for more information regarding this workaround. Another workaround is to use ToolsCalculate instead of using a formula. The trick I use is to have the total row as a separate table, separated from the main one by a paragraph with its Font size set to 1 point, and Hidden (under Format + Font), and its line spacing set to Multiple 0.1 (under Format + Paragraph). Because of the 0.1 line spacing, the gap between the tables is not noticeable, even on-screen, and even when ShowAll is switched on; so arguably it isn't really vital that you set the font to Hidden; but without doing that, the gap may just be noticeable on high resolution printers. Then use a bookmark in the SUM formula. It's a bit kludgy but it does work. One major benefit of this strategy (for things like Invoice and Quote templates) is that the user can subsequently add more rows to the main table simply by tabbing, and the formula will still work which they couldn't otherwise do. So supposing you've created two tables (the main table and the total row table) as follows:
62
Figure 1: This is actually two tables, separated by a 1 point, 0.1 line-spaced paragraph. As you can see, even with ShowAll switched on, the gap is invisible.
Select the main table, select Insert + Bookmark, call the bookmark Table1 and click Add. (If you had more tables of this sort you could bookmark the others with names such as Table2, Table3, etc). Then in the total cell, press Ctrl+F9, and within the field braces {}, insert the following formula:
{ SUM(Table1 F:F) \# "#,##0.00;- #,##0.00;''" }
Table1 in the formula refers to the name of the bookmark you've marked the main table with. The formula, being in a different table from the column it's totalling, wouldn't know which table you were referencing otherwise. The F:F bit means the 6th column from the left. The bit at the end of the formula:
;''"
... means that if there are no values in column F, don't display anything (otherwise it would display 0.00). I learnt that trick from Word MVP Cindy Meister. The total field will automatically update when you print, or go into Print Preview (provided you have Update fields switched on under Tools + Options + Print); and you can also update your fields at any time by Selecting All and pressing F9 (update fields) - which you could assign to a Toolbar button to make it more user-friendly. If the user might need to insert more such tables in the same document, you could make it more user-friendly still by storing the basic table layout, as an AutoText entry; and then using a macro to insert the AutoText entry, assign a bookmark to the main table (bearing in mind that the bookmark name needs to be different each time, so can't be stored in the AutoText entry itself), and insert the formula (which could not be stored in the AutoText entry, for the same reason). Formula Fields are covered in more detail in Word's Help.
63
64
Floating objects in Word 2000 table cells are vertically aligned wrongly
Whenever I insert a graphical object (picture, drawing object, etc.) into a Word 2000 table cell I lose the vertical formatting. The text is always aligned at the top of the cell, instead of being centered or at the bottom of the cell. Why, and what can I do about it?
Article contributed by Cindy Meister
This problem is due to Word2000 table text being able to wrap around a graphic and that negates the vertical cell alignment. Here's how to work around it. When you insert a graphic of any type that floats above the text (can be freely positioned on the page), it anchors itself to text within the document. (If you don't see an anchor symbol somewhere in the left margin when a graphic is selected, turn on the display of non-printing characters in Tools/Options/View.) When the anchor is in the table, you see the problem described; if it's outside the table, you get the correct vertical alignment. 1. Insert the graphic outside the table; make sure the anchor is outside the table. (If you can't see the anchor, click on the Show/Hide button to display non-printing characters). 2. Right-click on the graphic. 3. Go to Format AutoShape/Layout/Advanced. 4. Activate Lock anchor. Now the anchor will stay with the text outside the table. 5. Drag the graphic into the table.
65
I have a Name column which I want to split into FirstName, LastName how can I do it?
Article contributed by Dave
Rado
Word's sorting capability is fairly rudimentary, especially for those migrating to it from WordPerfect (though it's surprising how many people don't realize Word can sort paragraphs, not just tables or maybe not so surprising, given where the item is in the menus! The ability to sort on word 2 in field 3 would certainly be very useful (in Excel as well). I believe there has been a lot of demand for this capability to be added, so maybe it's on the way ... But there are various things you can do in the meantime. One is, write a macro. Another is to use Find and Replace to separate the text into fields (using tabs as the field separator). For instance, I often use the following trick if I'm emailed a spreadsheet with a Name column which I want to split into FirstName, LastName: The following assumes the column is in Excel, but of course it could just as easily be in a Word table. 1. Select the column in Excel and paste it into a blank Word document.
2. Select the column in Word (press Alt + Left mouse click), then press Ctrl+Spacebar to remove manual character formatting, and select Table + Convert Table to Text. 3. Use Find and Replace to replace any spaces with single ones:
In the Find what box type: ^w (or select the "Special" button and choose "White space) In the Replace with box type [space] (i.e. press the spacebar) Click Replace All 4. Next, you want to replace the spaces preceding the last names with tabs, in order to be able to convert back to a table separated by tabs. To allow for the possibility that, somewhere in the list, there might be some middle names or initials, select the Use wildcards check box in the Find and Replace dialog, and: In the Find what box type: (<*) ([! ]@)^13
66
In the Replace with box type: \1^t\2^p Click Replace All That will give you the following result (with non-printing characters displayed):
For more on using wildcard searches see: Finding and replacing characters using wildcards. Alternatively, if your original list was in the format: Major, Alan P. Then you don't need to use wildcards in order to insert the tabs in the right place In the Find what box type: ,[space] (type a comma then press the spacebar) In the Replace with box type ^t Click Replace All 5. Select the text (Ctrl+A) and select Table + Convert Text to Table.
You should find that the Word dialog suggests 2 columns and that text should be separated at tabs. If not that you don't have any rogue text or empty paragraphs selected at the end of the document. If there were any middle names or initials in the list, I fix these later by creating a MiddleName column in Excel and putting these orphans into it. 6. Type FirstName and LastName in the two cells in the top row of your new table.
Copy your Word table, Alt+Tab into Excel, insert an additional column to the right of the Name column, and paste. Sounds convoluted and I guess it is, but it doesn't take long I've fixed 1,000 record mail merge Data Sources in minutes using this method.
67
68
There are a couple of methods you can use for this. Using Excel, if you If you have it, is the easiest way, and you tend to get fewer import errors in Access if you use Excel. However, if you don't have Excel, you can convert your Word table into tab-delimited format, which you can import directly into Access. This is still pretty easy, although it does involve a few additional steps. Whichever method you use, make sure the first row of your table contains field names that uniquely describe the information in each column. If it doesnt, then place your cursor in the first row, go to Table/Insert Rows and add your field names.
Select the Word table and go to Table/Convert Table to Text Use the Separate the Text using Tabs option Go to File/Save As and change the Save as Type to Text only. Save and close the file. Open your Access database (create a new one if needed) Right-click an empty area of the Tables Object list and select Import Change the Files of Type to Text Files Select your text file you saved earlier and work through the Import Text Wizard Note that once you have your table in Access, you need to go to the Table design and review the data types and field sizes assigned and make the necessary changes.
70
You can download a sample template in Word 6/95 file format (29 KB). There is an example in it for items marked with an *asterisk. Code for automating numbering using Word fields can be found in the MOD article "Word Fields, Part II: Numbering Conundrums".
{ { {
}{
= HighNr -
{ {
{ SEQ } } } }
RevNrList
} }
Display: 10 9 8
{ Quote { Set ABC { = { ABC } + 1 } }{ SET ABC2 { IF { ABC } > 26 "{ IF { = MOD({ ABC }, 26) } = 1 "{ = { ABC2 } + 1 }" "{ ABC2 }" }" "{ ABC2 }" } }{ SET ABC1 { IF ABC1 < 26 "{ = { ABC1 } + 1 }" "1" } }{ If { ABC } < 27 "{ ABC1 \* ALPHABETIC }" "{ ABC2 \* ALPHABETIC }{ ABC1 \* ALPHABETIC }" } }
More information on how to use fields.
RESULT 2
Field set to generate relative cell reference { Quote { Set CellNr1 "a{ SEQ
71
B1 - C1 }
CellNr }" }{ Set CellNr2 "b{ SEQ CellNr \c }" }{ Set CellNr3 "c{ SEQ CellNr \c }" }{ = { Ref CellNr1 }*{ Ref CellNr2 }-{ Ref CellNr3 } } } { Quote { Set CellNr1 "a{ SEQ CellNr }" }{ Set CellNr2 "b{ SEQ CellNr \c }" }{ Set CellNr3 "c{ SEQ CellNr \c }" }{ = { Ref CellNr1 }*{ Ref CellNr2 }-{ Ref CellNr3 } } }
{ = A2 * B2 - C2 }
As in so many things, Word97's fields don't behave quite right. When you try to combine something in the SET bookmark with the SEQ field, the SEQ field increments by 2, instead of by 1, so you need this:
RESULT
Field set to generate relative cell reference { Quote { Set CellNr1 "a{ = { SEQ CellNr }/2}" }{ Set CellNr2 "b{ = { SEQ CellNr \c }/2}" }{ Set CellNr3 "c{ = { SEQ CellNr \c }/2}" }{ = { Ref CellNr1 }*{ Ref CellNr2 }-{ Ref CellNr3 } } }
{ = A1 * B1 - C1 }
The QUOTE field is not necessary, but it helps to keep everything together. The SET fields create bookmarks referenced in the formula. The SEQ fields generate the row numbers. The first one will update as it is copied down the table; the second and third are locked to the first by the \c switch.
72
switches, look under Switches; field switches; number formats in Word's Help Index.) But the program is limited to displaying the information for numbers less than one million. In order to display amounts in the millions as text, you need to use a combination of nested fields:
Example:
{ {
QUOTE SET r
= SET n 1999999
}{
}" "{ = int(n/1000000) \* cardtext } million { = MOD(n, 1000000) } }{ IF r = 0 "" "{ = r \* cardtext }" }" } \* caps \* CharFormat }
\*cardtext
Display: one million nine hundred ninety-nine thousand nine hundred ninety-nine
The QUOTE field keeps everything together. The number you want to work with is bookmarked in the SET field. Then you test whether the number is greater than one million. If it is, divide it by one million, then get the integer of this result for the words in millions. Next, determine the remainder and get the text for it. I can't take credit for this solution. It is the result of the combined efforts of numerous regulars in GO MSWORD on CompuServe. Thanks for you input, friends, as always :-)
73
74
Suppose you want to have a graph, such as a pie chart, that is linked to formfields in a protected document. In each formfield, the user will enter numbers. You want the graph to update to reflect the new data. And you want to use MS Graph instead of Excel, to keep the whole thing lightweight and self-contained. I know that most people use Excel to create graphs in Word documents, but I like using MS Graph. Like a compact car, it does most of what a charting tool needs to do without the expense or heavy duty lifting of a Nimitz-class Excel chart. It's lightweight and functional. But like Excel, it is also a completely different application, and that makes for some confusion. For example, many new users of Word intuitively expect MS Graph charts to be updateable from Word tables. Alas, they are not. An MS Graph graph is an embedded object. It cannot be linked to the data in a protected table in any way whatsoever. The chart that you see gets its values from a DataSheet that comes with the object. But you can use the following macro to do the charting updates, and the results are far easier to achieve and far faster to get than Excel results. You can use VBA to export the values in your table to the DataSheet in the MS Graph object. In English, you do this: 1. 2. 3. 4. 5. Get the values in the FormFields. Open the graph for editing. Put the FormField values in the appropriate DataSheet cells. Update the chart. Shut down MSGraph.
The code that follows does exactly that. I run it OnExit from the last FormField entered in the
75
form.
Public Sub UpdateChart() Dim oMSGraphWrapper As Word.InlineShape Dim oDoc As Word.Document Dim oMSGraphObject As Object Dim oDataSheet As Graph.DataSheet Dim iEntry1 As Long Dim iEntry2 As Long Set oDoc = ActiveDocument oDoc.Application.ScreenUpdating = False Set oMSGraphWrapper = oDoc.InlineShapes(1) iEntry1 = oDoc.FormFields("txtEntry1").Result iEntry2 = oDoc.FormFields("txtEntry2").Result oMSGraphWrapper.OLEFormat.Edit Set oMSGraphObject = oMSGraphWrapper.OLEFormat.Object Set oDataSheet = oMSGraphObject.Application.DataSheet With oDataSheet .Range("a1").Value = iEntry1 .Range("b1").Value = iEntry2 End With With oMSGraphObject.Application .Update .Quit End With oDoc.Application.ScreenUpdating = True Set oDataSheet = Nothing Set oMSGraphWrapper = Nothing Set oDoc = Nothing Set oMSGraphObject = Nothing End Sub
If you want to see how this works, just make sure you do three things: 1. 2. Have a table with two numeric FormFields named txtEntry1 and txtEntry2. Set at least one of the OnEntry or OnExit macros to the UpdateChart macro.
3. Set a reference to the Microsoft Graph 8.0 Object Library in the appropriate template in the Visual Basic Editor. (Under Tools + References).
76
77
78