[Solved] Launching AOO Basic procedure from a Calc click
Posted: Sat Nov 26, 2022 1:38 am
Sorry to post about something so fundamental, but I have been searching without success.
I wanted a very simple operation to update a couple of cell values when I choose e.g. by clicking in a cell in that row.
I will replicate this functionality across about 1000 rows, so the row will be an arg.
I had assumed I would use a push button, but I found recommendations to use a hyperlink, that's fine too.
(It was quite hard to find docs about coding that custom operation, because most information is about "function" which is defined as something that returns a value (which my code will not) and "macro" which is defined as a recording of a series of user actions. Mine is neither. I eventually did find some documentation on OO Basic that defines a "procedure" (identified in OO Basic by "Sub") which seems exactly what I want. I'm a programmer so I'm happy to study further to write that code; that's not my problem.)
My problem is how to call the OO Basic procedure from a Calc cell.
That seems a very trivial thing, but I can't see how to do it. There are a couple of helpful looking examples of hyperlinks with references to sun star etc followed by some kind of local code item identity - I doubted whether I needed the sun star thing but I tried it - Calc complained.
I have created a test procedure, stored in the document, by using Tools | Macros | Organise Macros | OpenOffice.org Basic, and can see the procedure (let's say it's called DoFoo) listed under MyMacros | FooMacros (let's say that's what I called the collection when I created it) | Module1 (must be some default because I didn't name that or even see that name until I browse after writing the procedure), as an "Existing macro" (so I guess a procedure is a macro after all, despite it not matching the documented definition of a macro.)
So I would guess my cell has to say something like =HYPERLINK(<some path corresponding to the structure above>) but I have not been able to find how to construct that link. Just guessing =HYPERLINK(DoFoo) results in #NAME?
I set macro security to run after warning and set the folder with the document to trusted so a macro can run - if I can call it.
Hopefully this is an easy one...
I wanted a very simple operation to update a couple of cell values when I choose e.g. by clicking in a cell in that row.
I will replicate this functionality across about 1000 rows, so the row will be an arg.
I had assumed I would use a push button, but I found recommendations to use a hyperlink, that's fine too.
(It was quite hard to find docs about coding that custom operation, because most information is about "function" which is defined as something that returns a value (which my code will not) and "macro" which is defined as a recording of a series of user actions. Mine is neither. I eventually did find some documentation on OO Basic that defines a "procedure" (identified in OO Basic by "Sub") which seems exactly what I want. I'm a programmer so I'm happy to study further to write that code; that's not my problem.)
My problem is how to call the OO Basic procedure from a Calc cell.
That seems a very trivial thing, but I can't see how to do it. There are a couple of helpful looking examples of hyperlinks with references to sun star etc followed by some kind of local code item identity - I doubted whether I needed the sun star thing but I tried it - Calc complained.
I have created a test procedure, stored in the document, by using Tools | Macros | Organise Macros | OpenOffice.org Basic, and can see the procedure (let's say it's called DoFoo) listed under MyMacros | FooMacros (let's say that's what I called the collection when I created it) | Module1 (must be some default because I didn't name that or even see that name until I browse after writing the procedure), as an "Existing macro" (so I guess a procedure is a macro after all, despite it not matching the documented definition of a macro.)
So I would guess my cell has to say something like =HYPERLINK(<some path corresponding to the structure above>) but I have not been able to find how to construct that link. Just guessing =HYPERLINK(DoFoo) results in #NAME?
I set macro security to run after warning and set the folder with the document to trusted so a macro can run - if I can call it.
Hopefully this is an easy one...