Home | Tips | Library | Other Authors | Other WP Sites | Writer's Links | Contact | Site Map | Donate

Barry MacDonnell's
Toolbox for WordPerfect

Macros, tips, and templates for Corel® WordPerfect® for Windows®
© Copyright 1996-2018 by Barry MacDonnell. All Rights Reserved.

Page updated Jul 28, 2017

Create a custom table with a macro

Download CUSTOMTBL.ZIP (v1.01; 04/02/14; 7,334 bytes)

Compatible with WordPerfect 9 and later versions

WordPerfect 11 users: See important information about using macros in the first release of WP11 (11.0.0.233) at the top of this page.

Downloading, Documentation, Modifications, and Support



Related pages -

•  See Using WordPerfect tables (lots of tips)

•  See various macros that process or use tables in the Library (search with Ctrl+F for "table" on that page)




Purpose and instructions

Create a custom table.wcm - This macro creates a custom table at the cursor position with your preferred default settings for the number of columns and rows, as well as the table's horizontal position, cell margins, cell widths, and cell format (numbers, currency, text, etc.)

Click the Download link in the left column and save the archive file (CustomTbl.zip) to any convenient folder on your computer. Then extract the Create a custom table.wcm macro and place it in your Default of Supplemental macro folder. (For additional help with this see the Downloading... link in the left column on this page.)

Then play the macro in a new document to see how it works. Enter some text in the cells, use the Tab key to move to the next cell (and in the last cell to add a new row), etc. You can also view it as it will print with File, Print Preview.

By default the macro creates a new 3-row, 3-column table centered on the page, using the Chicago Manual of Style format (i.e., no left or right table borders; a single-line for the top and bottom table border; no cell borders except a border at the bottom of the first row of cells).

You can easily modify it to suit your needs.

Modification and user preferences

Open the macro like any WordPerfect document to set your preferences in the redlined User Modification Area at the top of the macro's code.

Then click Save & Compile from the macro toolbar (or just File, Save on the main menu).


 
Tips

☼  This macro might best be added to the top menu, adjacent to the regular Create table command. See here for more on this. (You might name the menu selection "Create custom table".)

Alternatively you could assign it to a toolbar button or a keyboard shortcut, as explained here.

☼  See also several table tips on this page: "Using WordPerfect tables".

☼  Once a table exists -- and if the Numeric format of various cells has been modified (i.e., , by right-clicking in a cell and choosing a different Numeric Format) -- you might find later that you want to return all cells to (e.g.) Text format so that those modified cells do not automatically calculate or format themselves differently from plain text.

See Footnote 1 for a simple macro that can reset all cells in a table to Text format (and optionally remove cell/border lines) or any of the other 9 formats (General format is the program default for new tables).



Footnote 1

For existing tables, any customized cell's Numeric format setting takes precedence over any customized column or table-wide format setting.

Hence, here's a small macro that can change ALL cell formats in a given table to Text when you play the macro from inside that table. (The program's default for Numeric format is General, which is why entries like =2+3 are auto-calculated to produce 5 rather than simply display the math expression as plain text. It assumes you actually wanted to auto-calculate that entry because you use the equal sign.)

First: To copy this code into your WordPerfect program to create a working macro, see http://wptoolbox.com/tips/CopyCode.html.

Operation: Just place your cursor in a table and play the macro. (Always make a backup of the document before playing a macro to ensure it works as intended.)

Modification: You can set either or both of the two variables below to your preferences. vFormatType sets the type of Numeric format, and vLines allows removing border/cell lines.

- - -

// Macro begins here

// Set the default table numeric format and border/cell lines:
vFormatType:=9  // 0=General, 1=Integer, 2=Fixed(2 decimals), 3=Percent,
                         // 4=Currency, 5=Accounting, 6=Commas, 7=Scientific,
                         // 8=Date format, 9=Text only

vLines:=1           // 1=Keep any border and cell lines; 0=Remove them

If(Not ?InTable)
    Messagebox(;
    "Change all table cells format";
    "Ooops! Macro works only when cursor is in a table"; IconWarning!)
    Quit
Endif

Display(On!)
TableSelectOn (SelectionMode: Table!)
TableCellNumberFormat (FormatType: vFormatType)

If(vLines=0)
    TableBorderEditBegin ()
    TableBorder (NoBorder!)
    TableBorderEditEnd (State: Save!)
    TableCellLine (Position:Outside!; Style:NoLine!)
    TableCellLine (Position:Inside!; Style:NoLine!)
Endif

Prompt("Change Table Cells Numeric Format";
    "Done!"; InformationIcon!|NoButtons!|Beep!)
Wait(20)  // (wait 2.0 seconds)
EndPrompt

SelectOff
Quit

// Macro ends here

- - -