Getting Started Guide
A complicated example
I frequently copy rows and columns of data from a web site and format them as a
table in a text document. First, I copy the table from the web site to the clipboard. To
avoid strange formatting and fonts, I paste the text into a Writer document as
unformatted text. I reformat the text with tabs between columns so that I can use
Table > Convert > Text to Table to convert to a table.
I inspect the text to see if I can record a macro to format the text (remember the two
questions that I ask). As an example, I copied the FontWeight constants group from
the OpenOffice.org web site. The first column indicates the constant name. Each
name is followed by a space and a tab.
DONTKNOW The font weight is not specified/known.
THIN specifies a 50% font weight.
ULTRALIGHT specifies a 60% font weight.
LIGHT specifies a 75% font weight.
SEMILIGHT specifies a 90% font weight.
NORMAL specifies a normal font weight.
SEMIBOLD specifies a 110% font weight.
BOLD specifies a 150% font weight.
ULTRABOLD specifies a 175% font weight.
BLACK specifies a 200% font weight.
I want the first column to contain the numeric value, the second column the name,
and the third column the description. The desired work is easily accomplished for
every row except for DONTKNOW and NORMAL, which do not contain a numeric
value—but I know that the values are 0 and 100, so I will enter those manually.
The data can be cleaned in multiple ways—all of them easy. The first example uses
keystrokes that assume the cursor is at the start of the line with the text THIN.
1) Use Tools > Macros > Record Macro to start recording.
2) Press Ctrl+Right Arrow to move the cursor to the start of “specifies”.
3) Press Backspace twice to remove the tab and the space.
4) Press Tab to add the tab without the space after the constant name.
5) Press Delete to delete the lower case s and then press S to add an upper case
S.
6) Press Ctrl+Right Arrow twice to move the cursor to the start of the number.
7) Press Ctrl+Shift+Right Arrow to select and move the cursor before the % sign.
8) Press Ctrl+C to copy the selected text to the clipboard.
9) Press End to move the cursor to the end of the line.
10) Press Backspace twice to remove the two trailing spaces.
11) Press Home to move the cursor to the start of the line.
12) Press Ctrl+V to paste the selected number to the start of the line.
13) Pasting the value also pasted an extra space, so press Backspace to remove the
extra space.
Chapter 13 Getting Started with Macros 329










