[Solved] Add actions for command buttons

Discuss the spreadsheet application
Post Reply
Martin199
Posts: 3
Joined: Thu Mar 10, 2022 6:06 pm

[Solved] Add actions for command buttons

Post by Martin199 »

Hello.

So I'm trying to add some simple command buttons in Open Office calc, which I need to do the following two types of actions when pressed:
- Write the cell value from Cell A1 to Cell A2
- Print range B2:C3 if Cell A3 contains text; else print D2:E3

Thing is, I know neither the code for these actions, nor (and more importantly) where to put the code. I tried right-clicking and navigating all sorts of menus, but the "put the code for when you press the button" option is nowhere to be found, as far as I can tell. I found several "Event" menus, but none of them seem to refer to the button being pressed. Searched online, only got more and more frustrated.

So...help please? lol
Last edited by MrProgrammer on Mon Sep 12, 2022 6:08 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
OpenOffice 4.1.11 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Command Button Actions

Post by Zizi64 »

Thing is, I know neither the code for these actions, nor (and more importantly) where to put the code.
You can place the macro code into the actual document (then it will work in the actual document only); or you can place the code into a Module of the Standard library of the MyMacros (under the office software).

Start with studiying Andrew Pitonyak's free macro books.
https://www.pitonyak.org/oo.php

Try to write your first code in the Basic IDE: Tools - Macros - Organize macros...
I tried right-clicking and navigating all sorts of menus, but the "put the code for when you press the button" option is nowhere to be found, as far as I can tell. I found several "Event" menus, but none of them seem to refer to the button being pressed.
You can assign your macro code (subroutines) - located in the Modules - to the events of the control objects.

Here is a small sample file that contains a simple macro in the Module1, and it is assigned to an event of a Push Button:
HelloWorldMacro.ods
(9.63 KiB) Downloaded 80 times
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Post Reply