Four great OpenOffice.org macros

219

Author: Dmitri Popov

Using the built-in programming language you can write macros that expand OpenOffice.org’s capabilities and automate repetitive tasks. But before you venture into the world of variables, loops, and procedures, check out some existing macros; someone already may have written a macro that fits your needs. And since many good macros are released under GPL, you can also learn a thing or two by examining the code as well as adapt it to your needs.

You can find several OOo macro repositories on the Web. A few good ones to get started with are OOoMacros, Iannz macros, and OpenOffice.org Forum.

Impress Photo Album Creator

Impress Photo Album Creator allows you to quickly turn a folder with pictures into an Impress slide show. This macro can come in quite handy when you want to show your family members pictures from your recent trip to Paris, or you have to quickly create a product tour for your customers.

Installing and using Photo Album Creator is as easy as it gets. Download the macro, open the PhotoAlbumInstaller_1-2.sxc file, and press the Install button. Choose where to add the Photo Album menu (the default As Top Menu ‘Photo Album’ is a good choice), then restart OpenOffice.org. If the Photo Album menu doesn’t appear, quit OpenOffice.org and the Quickstarter, then launch them again.

To create a new slide show with Photo Album, choose Create Album from the Photo Album menu, select the folder with pictures, and press OK. The macro will create a new Impress presentation and insert every picture in the folder into a separate slide. When the macro is done, you can start the slide show by clicking on the Slide Show button or pressing the F5 key.

Trusted macros
By default, every time you open a document containing a macro, you have to choose whether you want to enable or disable macros, in order to prevent you from inadvertently running a macro that can contain malicious code. To change the default security settings, choose Tools -> Options, select OpenOffice.org -> Security, and press the Macro Security button. In the Security Level section, you can choose how OpenOffice.org should treat macros. The default level is Medium, which should work fine in most situations. You may also want to create a ‘trusted’ folder on your hard disk where you can store documents that contain macros. You can then specify the path to the folder under the Trusted Sources tab by adding the path in the Trusted file locations window.

CAL2QIF

Almost every personal finance package supports QIF format, which allows you to exchange financial data between different applications. Using the CALC2QIF macro, you can export data from your favourite finance application into a Calc sheet and vice versa. For example, if you use Grisbi to manage your finances, you can import your data into a Calc sheet and use it to create diagrams and perform advanced data manipulation.

Installing CALC2QIF is not particularly complicated; open the calc2qif.sxc document, press the Install button, and restart OpenOffice.org. To get the data into a Calc sheet, you must create a QIF file first. If you are using Grisbi, launch the application and choose File -> Export -> Accounts to QIF file, select the account you want to export, and press OK. Next, create a Calc sheet and choose Calc2Qif -> Import from QIF. Select the created QIF file and press Import. Now you can work with your financial data in Calc.

extendedPDF

extendedPDF allows you to export OOo documents into PDF format. Though OpenOffice.org has its own built-in PDF export feature, extendedPDF can convert Writer documents into PDFs that contain hyperlinks and bookmarks.

Although the installation of extendedPDF is not as straightforward as that of the other macros, the whole installation procedure is well documented, and it shouldn’t cause any problems. extendedPDF is available in three editions: Open, Professional, and Universal. A comparison table at JDiSoftware’s Web site can help you to choose the Edition that suits your needs. Before you install extendedPDF, download and install two additional packages: extendedPDF PostScript Printer and Ghostscript (both packages are available at JDiSoftware’s Web site). When you install extendedPDF Professional with OpenOffice.org 2.0, you will be prompted to enter the path to the user settings folder. In most cases, the path under Windows will be C:Documents and SettingsUser nameApplication DataOpenOffice.org2.

To configure extendedPDF, use Tools -> Add-Ons -> extendedPDF. The configuration dialogue window allows you to change the settings, including how extendedPDF treats hyperlinks, PDF security, and output quality. The configuration dialogue also contains a handy feature to copy notes into the PDF file. If you enable it, all the notes in the Writer documents will be converted into PDF notes.

OOoWikipedia

As its name suggests, OOoWikipedia allows you to select a word in the currently opened document and look it up in Wikipedia. The macro supports Wikipedia in different languages, and a simple tweak will allow you to use the macro with other online resources, such as Google, Ask Jeeves, and Answers.com.

Here is how to add Google to the macro. Install OOoWikipedia (see OOoWikipedia’s Web site). Go to Tools -> Macros -> Organize macros -> OpenOffice.org Basic. In the opened dialogue window, choose My Macros -> OOoWikipedia -> Module1, select any macro from the list, and press Edit. Scroll to the beginning of the macro, locate the const nbLangues=15 line and change it to const nbLangues=16 (this will increase the number of ‘entries’ that the macro can handle). Locate and copy the following code:

'en
CurLang=2
WikipediaConf(CurLang,0)="en"
WikipediaConf(CurLang,1)="English"
WikipediaConf(CurLang,2)="http://en.wikipedia.org/wiki/Special:Search?search="
WikipediaConf(CurLang,3)="&go=Go"
WikipediaConf(CurLang,4)="Enter a word to find:"
WikipediaConf(CurLang,5)="No browser linked to OOo"
WikipediaConf(CurLang,6)="Please fill the HTTP parameter located in the menu"
WikipediaConf(CurLang,7)="Tools -> Options -> OpenOffice.org -> Programmes Auxiliaires"
'needed for install process
WikipediaConf(CurLang,8)="About OOoWikipedia ..."
WikipediaConf(CurLang,9)="Tool offered under LGPL license"
WikipediaConf(CurLang,10)="OOoWikipedia Direct"
WikipediaConf(CurLang,11)="OOoWikipedia Choice"
WikipediaConf(CurLang,12)="Done!"
WikipediaConf(CurLang,13)="Many thanks to all translators"

Paste it right after the shown segment and change the first six lines as follows:

'Google
CurLang=16
WikipediaConf(CurLang,0)="en"
WikipediaConf(CurLang,1)="Google"
WikipediaConf(CurLang,2)="http://www.google.com/search?hl=en&q="
WikipediaConf(CurLang,3)="&btnG=Google+Search"

Save the changes and close the editor window. To check whether the macro works properly, select a word in the current document and press the OOoWikipedia button (the one with the tiny question mark). You should see a dialogue window with the newly added Google option. Select it and press the Wikipedia button. This should launch the default browser and display Google’s search results.

Since you can now use other resources, you might want to change the labels in the dialogue window. To do this, choose Tools -> Macros -> Organize Dialogs. Select My Dialogs -> OOoWikipedia -> Dialog1, and press Edit. To change the button label, double-click on the Wikipedia button, and change the value of the Label field in the Properties window. In a similar way you can change the dialogue window’s label.

If you want to share your modified OOoWikipedia with others, you can export it as a ready-to-use package. To do this, choose Tools -> Package Manager, select My Packages -> OOoWikipedia.zip, and use the Export button to save the package.

Dmitri Popov is a freelance writer whose articles have appeared in Russian, British, and Danish computer magazines.