Ask Your Question
0

Run Macro from Command Line

asked 2019-08-29 11:30:38 +0200

nSeixas gravatar image

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

edit retag flag offensive close merge delete

Comments

For reference: tdf#104441

Mike Kaganski gravatar imageMike Kaganski ( 2019-08-29 11:43:54 +0200 )edit

@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 ...(more)

Ratslinger gravatar imageRatslinger ( 2019-08-29 19:49:43 +0200 )edit

@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 ...(more)

nSeixas gravatar imagenSeixas ( 2019-08-29 20:11:04 +0200 )edit

@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 gravatar imageRatslinger ( 2019-08-29 20:37:36 +0200 )edit

@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!

nSeixas gravatar imagenSeixas ( 2019-08-29 20:48:21 +0200 )edit

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

Ratslinger gravatar imageRatslinger ( 2019-08-29 21:03:55 +0200 )edit

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.

Ratslinger gravatar imageRatslinger ( 2019-08-29 23:02:09 +0200 )edit

Yes @Ratslinger, that's another option, not ideal but its better than nothing...thanks :)

nSeixas gravatar imagenSeixas ( 2019-08-30 09:49:03 +0200 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2019-08-30 11:52:01 +0200

updated 2019-08-30 11:56:43 +0200

Command is "Call". If I'm understand the question aright, I call up other macro's or sub's, in other sub's, by the command "call" then the name of sub or macro. If a crated macro (sub) is named "Open_Box_2", I type a line in a sub...... Call "Open_Box_2". But all that is done, works, when all sub's (or macro's) are in the same file.

edit flag offensive delete link more

Comments

@Mark McLean, that's not what I want...I want to run the macro from a console command line, not call it from another Sub.

Thanks

nSeixas gravatar imagenSeixas ( 2019-08-30 12:20:19 +0200 )edit
0

answered 2019-08-29 11:41:25 +0200

Opaque gravatar image

updated 2019-08-29 11:44:10 +0200

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 (✔) next to the answer.

edit flag offensive delete link more

Comments

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

Thanks

nSeixas gravatar imagenSeixas ( 2019-08-29 11:44:12 +0200 )edit

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

Opaque gravatar imageOpaque ( 2019-08-29 11:49:27 +0200 )edit

@Opaque: 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)...

Mike Kaganski gravatar imageMike Kaganski ( 2019-08-29 11:58:01 +0200 )edit

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

Opaque gravatar imageOpaque ( 2019-08-29 12:04:49 +0200 )edit

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.

nSeixas gravatar imagenSeixas ( 2019-08-29 12:10:39 +0200 )edit

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.

Mike Kaganski gravatar imageMike Kaganski ( 2019-08-29 12:14:53 +0200 )edit

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

nSeixas gravatar imagenSeixas ( 2019-08-29 12:23:41 +0200 )edit

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

Mike Kaganski gravatar imageMike Kaganski ( 2019-08-29 12:26:33 +0200 )edit

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

nSeixas gravatar imagenSeixas ( 2019-08-29 12:29:56 +0200 )edit

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

Mike Kaganski gravatar imageMike Kaganski ( 2019-08-29 12:34:08 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-08-29 11:30:38 +0200

Seen: 91 times

Last updated: Aug 30