open files automatically

There's no need to automate Calc (or LO)

simply create a file
name it something like 'autostartLibreoffice.bat'
(or anything else, as long as the name ends in '.bat'

The contents of this file should be the names of the files you want to be opened.

so, something like (other locations are OK too ;):
"C:\Users\Luuk\My Documents\TEST1.ods"
"C:\Users\Luuk\My Documents\TEST1.odt"

When you doubleclick the 'autostartLibreoffice.bat' file it will open the 'TEST1'-document, and the 'TEST1'-calcsheet.

BTW, it should be possible to play the same 'trick' on any other OS, because above example applies to Windows..... :wink:

Hi Luuk

Luuk wrote

There's no need to automate Calc (or LO)

simply create a file
name it something like 'autostartLibreoffice.bat'
(or anything else, as long as the name ends in '.bat'

That has been suggested before. The OPs request is that LibreOffice opens
all files stored in a given folder. This means that he can add/remove files
from the folder as needed without having to edit a script/batch file.

Sure, just change the script to:

@ECHO OFF
CD /D "C:\Users\Luuk\My Documents\AutoStart"
FOR %%f IN (*.*) DO START "" "%%f"

Assuming the directory "AutoStart" is the directory containing the files you want to open

Save in: <LibreOffice>
Event: <Start Application>
Macro: MyMacros.Library.Module.onApplicationStart

Hi Andreas,

Your Star Basic macro looks very interesting. It is not super complex (initialization, a loop, and a super simple supporting function). Has anyone given it a test drive?

As I read the macro, the while loop looks suspect. Isn't it testing the length of a directory name [ dir("path/file.ext") ] instead of a file name? And, won't it operate on no more than one entity? I thought the idea was to automatically open zero or more office document files when soffice starts running.

It also could probably be made more robust by adding a supporting function that validates the file's extension. Just a thought.

File name extensions are meaningless. LibreOffice tries to open any file
regardless of its extension. Rename a file to .xyz and open with
LibreOffice.
My code should have an error handler for unsupported (possibly broken)
files so the loop can continue in case of any error. That's it.

(I intend this reply to be off list)

Thank you.

It has probably been more than 20 years since I studied any flavor of Basic and I have not been able to find what dir("path/file.ext") or dir() are supposed to do. That is why I said that the "while" loop appears to be suspect. My guess is that the former returns "path/" while the latter returns an empty string. I must be wrong since that would prevent the macro from accomplishing the desired task. But, then again, I fail to see any result when I attempt to use this macro. Maybe I need to do more than exit from LO before I start it again in order to activate the Subroutine?

Hi Andreas, all

Andreas Säger wrote

Is there a way to make it autorun on start?

>Customize... [Events]
Save in:
<LibreOffice>
Event:
<Start Application>
Macro: MyMacros.Library.Module.onApplicationStart

Brilliant! That worked perfectly. Thank you, Andreas!

Thomas Blasejewicz, there you have it. Two possible solutions: Andreas'
macro set to AutoStart (which works on any OS) OR Luuk's batch file (written
for Windows but it is probably easy to convert for Linux...)

Hope one of the solutions works for you.

Oh no. It's not that easy because LO tries very hard to open "wrong"
files (e.g. big multi-media) without throwing any error.
Let's keep it simple. Don't put any files into that folder that do not
deserve to be in there.

(I intend this reply to be off list)

Thank you.

It has probably been more than 20 years since I studied any flavor of Basic and I have not been able to find what dir("path/file.ext") or dir() are supposed to do. That is why I said that the "while" loop appears to be suspect. My guess is that the former returns "path/" while the latter returns an empty string. I must be wrong since that would prevent the macro from accomplishing the desired task. But, then again, I fail to see any result when I attempt to use this macro. Maybe I need to do more than exit from LO before I start it again in order to activate the Subroutine?

How to install a code snippet: