OpenOffice.org OpenOffice - 3.0 Quick Start Guide Page 373

  • Download
  • Add to my manuals
  • Print
  • Page
    / 433
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 372
CreateUnoService accepts the name of a service and it tries to create
an instance of that service. On completion, the dispatcher variable
contains a reference to a DispatchHelper.
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
Declare an array of properties. Each property has a name and a value.
In other words, it is a name/value pair. The created array has one
property at index zero.
dim args1(0) as new com.sun.star.beans.PropertyValue
Give the property the name “Text” and the value “Andrew Pitonyak”,
which is the text that is inserted when the macro is run.
args1(0).Name = "Text"
args1(0).Value = "Andrew Pitonyak"
This is where the magic happens. The dispatch helper sends a dispatch
to the document’s 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.
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
Finally, the end of the subroutine.
end sub
Creating a macro
I usually ask two questions before recording a macro:
1) Can the task be written as a simple set of commands?
2) Can the steps be arranged such that the last command leaves the
cursor ready for the next command?
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
Chapter 13 Getting Started with Macros 373
Page view 372
1 2 ... 368 369 370 371 372 373 374 375 376 377 378 ... 432 433

Comments to this Manuals

No comments