O'Reilly logo

Writing Word Macros, Second Edition by Steven Roman PhD

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Example: Creating Tables from Word Lists

I will conclude our discussion of tables with an example, one that was promised in the Preface to the book. Let me first recap the situation.

In writing this book, I was faced with the problem of turning long columns of words into tables. The built-in ConvertToTable command was not flexible enough for my needs for three reasons.

First, I wanted the items to be placed in the table in column-major order (the first column is filled first), rather than in row-major order (the first row is filled first). Second, I wanted to choose the number of columns based on the number of words (cells), so I needed a report on the word count before I made the choice of the number of columns. Finally, I wanted a row at the top of the table for a title.

To illustrate, I wanted to be able to select the following column of words:

Border
Cell
Column
Document
Font
Options
PageSetup
Paragraph
ParagraphFormat
Range
Row
Selection
Style
Table
Template
Window

and then be presented with a dialog box as shown in Figure 16-5. Then, if I entered 3 for the number of columns and hit the OK button, I wanted the table shown in Figure 16-6.

Table-making dialog box

Figure 16-5. Table-making dialog box

Three-column table produced from a column of text

Figure 16-6. Three-column table produced from a column of text

The code is shown in Example 16-1. (I think that you should get a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required