Page 1 of 1

Please point me to Calc Basic API tutorials...

PostPosted: Wed Feb 20, 2008 2:03 am
by Motdepasse
Welcome beginner. Please answer all of the questions below which may provide information necessary to answer your question.
-----------------------------------------------------------------------------------------------------------
Which version of OpenOffice.org are you using? 2.3.1
What Operating System (version) are you using? Windows 2000 w/most recent service packs etc.
What is your question or comment?
I desperately need help with using the basic API for Calc. I've probably had to many years using VBA with Excel as nothing in the OpenOffice documentation makes any sense to me. Neither StarOfficeBasicGuide nor StarOfficeBasicTutorial are helpful. The tutorials seem to be just code fragments with key pieces of code missing. As an example the Guide has the following code fragment but it is not clear to me form the discussion in the document what statement or statements are missing as the code will not execute as written.

Dim Sheets As Object
Dim SheetNames
Dim I As Integer
Sheets = Spreadsheet.Sheets
SheetNames = Sheets.getElementNames
For I=LBound(SheetNames) To UBound(SheetNames)
MsgBox SheetNames(I)
Next I

I've searched for OpenOffice Calc API tutorials at the beginner level but havn't found anything that helps.

Thanks for any help.

Re: Please point me to Calc Basic API tutorials...

PostPosted: Wed Feb 20, 2008 3:36 am
by kingfisher
You would be helped, I believe, by Andrew Pitonyak's macro document, the Xray tool and the SDK. You will find a collection of relevant links on a wiki page. You will find the SDK on OO mirrors and the Xray tool through ooomacros.org.

Re: Please point me to Calc Basic API tutorials...

PostPosted: Wed Feb 20, 2008 5:27 pm
by Motdepasse
kingfisher wrote:You would be helped, I believe, by Andrew Pitonyak's macro document, the Xray tool and the SDK. You will find a collection of relevant links on a wiki page. You will find the SDK on OO mirrors and the Xray tool through ooomacros.org.


Thanks for the wiki tip; I'll give it a try. I've looked through a lot of the wiki stuff already but had given up after finding little of value, perhaps Pitonyak is the key to my understanding.

Re: Please point me to Calc Basic API tutorials...

PostPosted: Wed Feb 20, 2008 7:08 pm
by Motdepasse
After a little further searching I found a complete working example on how to get access to worksheets from a "Basic" macro. By adding the two lines indicated below everything works as expected. This change also gives access to all the cells on all the sheets.

It is such a simple but important addition to the code that I'm at a loss to understand why it was not included in the original fragment. The entire StarOfficeBasicGuide.pdf file that listed the fragment did not even include the entry for "ThisComponent"!

Dim Sheets As Object
Dim SheetNames
Dim I As Integer

'**************************************
Dim Spreadsheet as object
Spreadsheet = ThisComponent
'**************************************

Sheets = Spreadsheet.Sheets
SheetNames = Sheets.getElementNames
For I=LBound(SheetNames) To UBound(SheetNames)
MsgBox SheetNames(I)
Next I

 Edit: Hagar: removed the first post quoted, no need of it. 

Re: Please point me to Calc Basic API tutorials...

PostPosted: Wed Feb 20, 2008 10:02 pm
by Hagar Delest
Moved to the Macros forum (there is a link to the Basic guide top of page).

Thanks to add '[Solved]' in your first post title (edit button) if your issue has been fixed.