Run Macro from Command Line

Hi all…

I have a .odb file that contains a macro and I’m trying to call this macro from command line, however without success.
That’s what I’m trying.

soffice “C:\Users\nuno\AppData\Roaming\LineMap.odb” “macro://LineMap/Reports.Report.genRep”

It launch the odb file but doesn’t fire the macro.
I’m running Libroffice 6.2.4.2

ps. If I run the macro manually it works. it’s just a message box.

Thanks

For reference: tdf#104441

@nSeixas,

Have read this entire post multiple times and gave time to ponder the situation. Do understand the bottom line problem of the macro not being executed & the need for a fix there. However the confusing issue is some of the commenting on a current solution. Don’t want to install macros on each system (just an extension but OK - accept your wishes) but then there is the creation of an .odt with a macro which is to be able to run another macro.

Now what I see missing here is ‘the goal’. What is it you are attempting to do. Such as “Have the user do X to run a report vs having to open the Base file”.

Can you elaborate a bit on this as there may be a different solution. It appears your command line needs to be different for each user. Is each user using same .odb (ie copy of), reports, etc.?

@Ratslinger You are right…

Ok…I’m developing a software that will generate a few different reports (MapBasic and c#).

When the user click in a report it export the data as DBF into a folder and then I have the base file that takes the data from the DBF files and generate a report.

My goal is: the user press generate report X in my software and it just show the report output file (calc or write).

At this moment to archive that I have a macro in My Macros that receive two parameters, the odb file path and the report name and then I open that document and launch the the report.

To call the macro I use the command line, but it doesn’t work with odb files, so I need to put the macro in My Macros for every client.

Ps. I tried to use the API for c# but without success (to load the odb file and launch the report)…

@nSeixas,

Here is why I asked. Instead of having a macro in an .odt calling a macro in an .odb, possibly eliminate the .odb macro and just have one from an odt. Have opened Base reports from Writer using the macro by @Kridtbandit in this post → how to open Base reports based on queries in standalone.

Don’t yet comprehend all your needs (don’t think I need to either) but possibly this may be of use to you. Seems it has some potential for your situation.

@Ratslinger that´s what I tried, and it worked (just one macro in a blank odt file), the problem is that it will open the odt file (blank) and the report output file…not ideal!

Will experiment with later. Let you know if I find any solution.

One other suggestion. While not the best solution, at the end of the macro add ThisComponent.close(1). That will close the blank .odt & still leave the report visible.

Edit: Just tried at beginning of macro and blank screen appeared for shorter amount of time. Report still generated.

Yes @Ratslinger, that’s another option, not ideal but its better than nothing…thanks :slight_smile:

Hello

may be you missed that there need to be three /// after the keyword macro - try:

soffice "C:\Users\nuno\AppData\Roaming\LineMap.odb" macro:///LineMap/Reports.Report.genRep

If the answer is correct or helped you to fix your problem, please click the check mark (:heavy_check_mark:) next to the answer.

Unfortunately that doesn’t change anything. Same behaviour. No macro being fired.

Thanks

Ah - now I see. your path doesn’t fit to the format specification Library.Module.Macroname

@anon73440385: the macro: URI does fit to //authority/Library.Module.Macroname spec - where authority is docname; so it possibly should work - but it doesn’t (also in my testing)…

It also only works form me, if I put the macro into global section “My Macros”

Mike have you tried and is not working as well?

There’s something wrong I believe…

What I need is to generate a report that is inside that odb file! I have a macro in My Macros that receive a doc name (the odb in that case) and a report name and it works, the problem is I have to install libreoffice in multiple PC’s and I really don’t like the idea of install and then import Macros if I can have a macro inside a file.

I have debugged, and in SfxMacroLoader::loadMacro, the call to SfxObjectShell::GetFirst() returns nullptr - it means that the open database isn’t listed among open shells - and thus doesn’t offer the expected functionality (unlike Writer or Calc components). You may file an enhancement request to add such functionality to Base.

1 Like

Ok Mike…Thank you so much…In that case I can create a odt dummy file with a macro where I pass the odb file path and report name and it solves my problem…Thanks you again

But possibly better assign the macro in the DB to the Open Document event?

I thought about that. But then how can I pass the name of the report that I want to open?

Then please do file a request to bug tracker, and post a ref# here.