Operation Manual

This is where the magic happens. The dispatch helper sends a dispatch to the document frame
(stored in the variable named document) with the command .uno:InsertText. The next two
arguments, frame name and search flags, are beyond the scope of this document. The last
argument is the array of property values to be used while executing the command InsertText.
end sub
The last line of the code ends the subroutine.
Creating a macro
When creating a macro, it is important to ask two questions before recording:
1) Can the task be written as a simple set of commands?
2) Can the steps be arranged so that the last command leaves the cursor ready for the next
command or entering text or data into the document?
A more complicated example of a macro
A common task is to copy rows and columns of data from a web site and format them as a table in
a text document as follows:
1) Copy the data from the web site to the clipboard.
2) To avoid strange formatting and fonts, paste the text into a Writer document as unformatted
text.
3) Reformat the text with tabs between columns so that it can be converted into a table using
Table > Convert > Text to Table on the main menu bar.
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.
Figure 338: Example of copied data
With the two questions given above in mind, inspect the text to see if a macro can be recorded to
format the text. An example of copied data showing the FontWeight constants group from the API
web site (Figure 338). The first column in this example indicates a constant name and each name
is followed by a space and a tab, and each line has two trailing spaces.
The first column in the table should contain a numeric value, the second column the name, and the
third column the description. This conversion is easily accomplished for every row except for
DONTKNOW and NORMAL, which do not contain a numeric value, but the values are between 0
and 100 and can be entered manually.
342 | Getting Started with LibreOffice 4.0