Hi all, is there a command line interface for the Basic Editor? I would like to edit and save macros for a doc file using the command line, if possible.
Not really, as far as I’ve been able to determine. However…
You can edit a macro in a text editor outside of the Basic Editor, and you can run a macro from the command line.
For example, say you create a (really) simple macro in the Basic Editor within Standard.Module1…
Sub Main
print "This is a macro!"
End Sub
…and then close LO.
Then, as presented on page 135 of Andrew Pitonyak’s “Useful Macro Information For OpenOffice.org” (http://www.pitonyak.org/AndrewMacro.odt), you can run the macro from the command line like this…
soffice macro:///standard.module1.main
The result is a dialog box with the message “This is a macro!”
Then, if you go to the directory containing the macro in your LO profile (your directory location may differ)…
cd ~/.config/libreoffice/4/user/basic/Standard
…you can edit the file corresponding to the module (in this case Module1.xba) in any text editor (vi, for example). So, say you edit the file, add the word “DEFINITELY” to the print statement, save the file, and run again as above. Then you’ll get a dialog box with the message “This is DEFINITELY a macro!”
Whatever changes you make to macros outside of LO will show up in those macros within LO when it’s next opened. But if you edit macros while leaving LO open, changes to those macros won’t show up in LO until it’s closed and then opened again. And I don’t know what’ll happen if you edit a macro outside of LO with LO open and edit the same macro within LO before closing and then opening LO to pick up the changes from outside, so I’d be careful doing that.
@techsquirrel’s answer interprets the question as asking about system-wide macros. However if “for a doc file” means macros that are embedded in the file itself, then that will not work.
To modify macros built into an ODT file, unzip the ODT file and then find the macros inside XML files. This may also be possible with DOCX, although I have not tried it.
It is not possible to unzip the DOC format. I do not think there is any good way to modify macros embedded in DOC files from the command line. Even Apache POI does not support macros.
One final possibility: Create a macro that works with com.sun.star.script.BasicIDE, the Basic Editor component. See for example http://140.211.11.67/en/forum/viewtopic.php?t=6458&p=30769. This looks like it could work if the editor is already open, although I do not see an example of how to automate opening it.