Book Image

Learn OpenOffice.org Spreadsheet Macro Programming: OOoBasic and Calc automation

By : Dr Mark Alexander Bain
Book Image

Learn OpenOffice.org Spreadsheet Macro Programming: OOoBasic and Calc automation

By: Dr Mark Alexander Bain

Overview of this book

<p>Adding macros to your spreadsheets enables you to add data processing features to your work, automate repetitive tasks, and even create complete data-driven programs that use the spreadsheet as their back end.<br /><br />This book teaches the OOoBasic language and the Calc object model, so that you can manipulate spreadsheets and data from within your programs. You will also see how to create dialog boxes and windows for friendly user interfaces, and how to integrate your spreadsheets with other applications, for example writing spreadsheet data to a document, or capturing data from a database, and using the spreadsheet for generating advanced calculations and reports.<br /><br />Calc is OpenOffice.org's spreadsheet module. Like the rest of OpenOffice.org Calc can be programmed using the built-in language OOoBasic. Both simple macros and complex applications can be developed in this language by controlling Calc through its object model. The book is compatible with the commercial version of OpenOffice.org, StarOffice, and the StarBasic language.</p>
Table of Contents (15 chapters)
Learn OpenOffice.org Spreadsheet Macro Programming
Credits
About the Author
About the Reviewer
Preface

Comparing VBA and OOo Basic Code


If you look through the VBA code and OOo Basic code we've seen so far, you'll see that there are a number of obvious differences:

  • There appear to be more lines of OOo Basic code required to do the same job.

  • In VBA, a cell can contain either values or formulas, but not strings.

  • The cell positioning is different.

Simplifying Code

In actual fact, you can re-write the OOo Basic code so that it uses (almost) the same number of lines as VBA:

'Standard OpenOffice.org Basic
Dim Sheet as Object
Sheet = thisComponent.Sheets("Sheet1")
Sheet.getCellByPosition(1,1).String = "B2"
Sheet.getCellByPosition(1,2).String = "B3"
'VBA code
Sheets("Sheet1").Activate
Cells(1,1).Value = "=2*3"
Cells(1,2).Value = "B1"

You can even re-write it so that it uses less lines of code than the VBA:

'Standard OpenOffice.org Basic
thisComponent.Sheets("Sheet1").getCellByPosition(1,1).String = "B2"
thisComponent.Sheets("Sheet1").getCellByPosition(1,2).String = "B3"
'VBA code
Sheets("Sheet1").Activate...