O'Reilly logo

Learn OpenOffice.org Spreadsheet Macro Programming by Dr. Mark Alexander Bain

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required