[Solved] Can I daisy chain macros within the same module

Discuss the spreadsheet application
Post Reply
robbyn
Posts: 62
Joined: Sat Jun 26, 2021 10:01 pm

[Solved] Can I daisy chain macros within the same module

Post by robbyn »

Instead of trying to combine recorded macros into one macro, can I put something at the end of the first that means the second will be run automatically, without getting reports that names and values have already been defined?
Last edited by Hagar Delest on Wed Sep 08, 2021 1:46 pm, edited 1 time in total.
Reason: tagged solved.
Libreoffice v7.2.0.4 on Ubuntu 20.04 Locale en-GB
Matareuz
Posts: 23
Joined: Fri Nov 20, 2020 4:33 pm
Location: Venezuela

Re: Can I daisy chain macros within the same module

Post by Matareuz »

You could write "Call *Macro's name* " in the last line of the first macro to call the second one.
LibreOffice 6.3.2.2 Windows 7 Ultimate
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can I daisy chain macros within the same module

Post by Villeroy »

You should learn some programming basics, not by copy/paste, not by playing around, not by forum questions. Consult books, online tutorials, a real life teacher can transfer conceptual knowledge instead of incoherent pieces. It may be difficult to find any books on Basic because Basic is a language of the 90ies. With Python your can script anything including your office suite.

This is more or less the same in all procedural languages:

Code: Select all

Sub Main()
MyMacro1
MyMacro2
MyMacro3
End Sub

Sub MyMacro1()
REM dummy
End Sub

Sub MyMacro2()
REM dummy
End Sub

Sub MyMacro3()
REM dummy
End Sub
Same in Python

Code: Select all

def Main():
    MyMacro1
    MyMacro2
    MyMacro3

def MyMacro1():
    # dummy
    pass


def MyMacro2():
    # dummy
    pass

def MyMacro3():
    # dummy
    pass
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
robbyn
Posts: 62
Joined: Sat Jun 26, 2021 10:01 pm

Re: Can I daisy chain macros within the same module

Post by robbyn »

I spent about 20 years programming in DBase 3. I know it well, but I have not found it available in Ubuntu.

Phrases like the following are difficult for me to understand conceptually.

document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args4(0) as new com.sun.star.beans.PropertyValue

What I need to do nowadays can be covered by a combination of the spreadsheet and recorded macros. I am able to make very complex conditions work with the action run by a recorded macro. However I also will slowly introduce python or basic as needed.

Thank you for your continued support.
Libreoffice v7.2.0.4 on Ubuntu 20.04 Locale en-GB
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can I daisy chain macros within the same module

Post by Villeroy »

https://wiki.openoffice.org/wiki/Docume ... Office.org

StarBasic's ThisComponent is the Model
ThisComponent.CurrentController() is the currently active View on the Model. There are more views when you call menu:Window>New Window
ThisComponent.CurrentControler.Frame is the containing frame of a view and its model.
objFrame.Controller.Model goes the other way round.

StarBasic's StarDesktop is the collection of all frames in this office suite.

The MRI extension lets you explore the hierarchy of all objects so you can lookup all the properties and methods of a given object.
[Tutorial] Introduction into object inspection with MRI

Dispatch macros simulate clicks in the user interface. They are very limited and poorly documented.
document = ThisComponent.CurrentController.Frame is misleading. ThisComponent is the document.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
robbyn
Posts: 62
Joined: Sat Jun 26, 2021 10:01 pm

Re: Can I daisy chain macros within the same module

Post by robbyn »

Thank you for that explanation.

I feel I should explain why I would want to join macros together. I have been trying to do a series of standard actions which involve many steps all done together. Ideally they should be in one long macro, but It is very easy to miss out a step and have to redo the whole macro. Following your previous advice relating to hidden columns containing parts of a formula, I thought I would break the macro into sub macros and then join them together by a daisy chain.
Libreoffice v7.2.0.4 on Ubuntu 20.04 Locale en-GB
User avatar
Lupp
Volunteer
Posts: 3548
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Can I daisy chain macros within the same module

Post by Lupp »

Code: Select all

Sub macro1()
...
...
...
macro2()
End Sub

Sub macro2()
..
...
macro3()
End Sub

Sub macro3()
...
...
MsgBox("Done!")
End Sub
Is this what you would call a "daisy chain of 3 macros"?
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
robbyn
Posts: 62
Joined: Sat Jun 26, 2021 10:01 pm

Re: Can I daisy chain macros within the same module

Post by robbyn »

Yes, that is my idea of a daisy chain.

Thank you all for your help.
Libreoffice v7.2.0.4 on Ubuntu 20.04 Locale en-GB
Post Reply