[Solved] Can I run multiple macros as a single process?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Vexed
Posts: 187
Joined: Sun Feb 08, 2009 1:24 am
Location: Virginia, USA

[Solved] Can I run multiple macros as a single process?

Post by Vexed »

I have 4 macros that update my spreadsheet. They must be executed in the same order to yield the correct end result. The order of the macros never changes. Is there a way that I can somehow link these macros to run with a single command? There is one complication, one of the macros opens the Insert -> Sheet From File option which then requires me to enter (paste) the data string (the file to be inserted) and then to execute "Enter" 3 time to complete the insert process... The data that I insert is always the same but this step always seems to thwart my efforts to make these 4 macros operate via a single command...

Is there a way to combine the function of these 4 macros into a single process?

Any help you can provide will be appreciated...
Last edited by Vexed on Mon Jun 01, 2009 5:00 am, edited 1 time in total.
OOo 2.4.X on Ms Windows XP
User avatar
squenson
Volunteer
Posts: 1885
Joined: Wed Jan 30, 2008 9:21 pm
Location: Lausanne, Switzerland

Re: Can I run multiple macros as a single process?

Post by squenson »

Why not create a new macro like this:

Code: Select all

Sub MyMacroScheduler
    MyMacro1
    MyMacro2
    MyMacro3
    MyMacro4
End Sub
LibreOffice 4.2.3.3. on Ubuntu 14.04
Vexed
Posts: 187
Joined: Sun Feb 08, 2009 1:24 am
Location: Virginia, USA

Re: Can I run multiple macros as a single process?

Post by Vexed »

I don't understand the example you provided but I have initiated "Record Macro" and then activated each macro along with the various steps and then "Stop Macro Record", then saved that as a new macro... When I activate this new consolidated macro it doesn't work...
OOo 2.4.X on Ms Windows XP
User avatar
squenson
Volunteer
Posts: 1885
Joined: Wed Jan 30, 2008 9:21 pm
Location: Lausanne, Switzerland

Re: Can I run multiple macros as a single process?

Post by squenson »

A macro is a small program and you can either create it automatically with the macro recorder, or by typing the commands yourself. When you created each macro, you gave it a name, like MyMacro1, MyMacro2, etc. Each macro contains one or several actions, each action being itself represented by one or several lines of code.

If you are sure that each macro does exactly what you want, you can now create manually a small program that will execute these four macros in sequence. For that purpose, click on the menu Tools > Macros > Organize Macros > OpenOffice.org Basic, select the module where you stored your automatically recorded macros and create at the top a new macro by typing

Code: Select all

Sub MyMacroScheduler
    MyMacro1
    MyMacro2
    MyMacro3
    MyMacro4
End Sub
Obviously, adapt the macro names to your own names. Now, go back to your main document and click on Tools > Macros > Run macro and select MyMacroScheduler in the list. It will execute in sequence the macros you have previously recorded.
LibreOffice 4.2.3.3. on Ubuntu 14.04
Vexed
Posts: 187
Joined: Sun Feb 08, 2009 1:24 am
Location: Virginia, USA

Re: Can I run multiple macros as a single process?

Post by Vexed »

Thanks.

I understand... Before I implement your suggestion there is one aspect of my original post that is not resolved by simply combining my existing macros via the process you cite... One of the macros in my sequence requires me to "paste" a string that was copied by a previous macro and then to manually hit "Enter" 3 times... The only way I've been able to get the "paste" command to work is to use CTRL V and then follow that with the 3 "Enter"s... and I've never got "macro record" to recognize the 3 "enter"s... If I combined my existing macros via the process you cite I would still need to perform these manual functions (which isn't much better than the process I currently use)...

Suggestions?
OOo 2.4.X on Ms Windows XP
User avatar
squenson
Volunteer
Posts: 1885
Joined: Wed Jan 30, 2008 9:21 pm
Location: Lausanne, Switzerland

Re: Can I run multiple macros as a single process?

Post by squenson »

The macro recorder is far from being perfect and as you have noticed, it does not record all the commands. In your case, the only way is to write the missing part manually, using the Basic macro language. A good book to start: http://www.pitonyak.org/AndrewMacro.odt.
LibreOffice 4.2.3.3. on Ubuntu 14.04
Vexed
Posts: 187
Joined: Sun Feb 08, 2009 1:24 am
Location: Virginia, USA

Re: Can I run multiple macros as a single process?

Post by Vexed »

Wow, that's a mighty big document to read to solve such a small problem... Frankly, it's easier for me to push a few extra keys then to sift thru all of that data and learn a new language just to save a few key strokes... Thanks for your input and pointing me in the direction of a possible solution but the ultimate solution I seek just ain't worth the research effort... What I got works, its just not as efficient as it could be.

I'll mark this as solved but only because I'm too lazy to see if that 200 page tutorial would actually lead me to a solution.
OOo 2.4.X on Ms Windows XP
Post Reply