Page 1 of 1

Macro to print documents in the same directory

Posted: Mon Aug 14, 2017 2:34 pm
by OOKapitan
Hello.
        I'm currently working in OpenOffice Calc, and I often have to print more than 40 files at once. Select all, PCM, printing does not work for me. Tell me, please, can there be a macro that allows you to print all the files in the same folder in which the file is located, where does this macro run from? I used to work in Excel, but at work only OpenOffice is installed, so now I'm working on it. If I know more or less excel macros, then I do not understand anything in OO macros. Help me please.

Re: Macro to print documents in the same directory

Posted: Mon Aug 14, 2017 2:59 pm
by JohnSUN-Pensioner
Not the answer, just a little explanation: when OOKapitan writes "PCM", he meant the right click of the mouse

Re: Macro to print documents in the same directory

Posted: Mon Aug 14, 2017 3:02 pm
by OOKapitan
JohnSUN-Pensioner wrote:Not the answer, just a little explanation: when OOKapitan writes "PCM", he meant the right click of the mouse
So it is not a mystake.

Re: Macro to print documents in the same directory

Posted: Mon Aug 14, 2017 3:10 pm
by Zizi64
If I know more or less excel macros, then I do not understand anything in OO macros.
This task requires a quite complex macro.
I suggest you: Hire somebody to write this macro for you.

There is a section of this Forum, named: Paid support.

viewforum.php?f=53

Re: Macro to print documents in the same directory

Posted: Mon Aug 14, 2017 3:14 pm
by OOKapitan
Ho is able easilly to write such mscro, please, write me this macros to me.

Re: Macro to print documents in the same directory

Posted: Mon Aug 14, 2017 3:18 pm
by RoryOF
I think this can be done quite easily with a macro at the Operating System level. OpenOfice can take command line arguments, one of which is to print a file or files passed as arguments.
https://wiki.openoffice.org/wiki/Framew ... _Arguments

It should be simple to write a Windows batch file to read a directory, t hen feed each file name into the OO command line until there are no more files left.

Re: Macro to print documents in the same directory

Posted: Mon Aug 14, 2017 3:38 pm
by RoryOF

Re: Macro to print documents in the same directory

Posted: Mon Aug 14, 2017 3:43 pm
by OOKapitan
RoryOF wrote:It should be simple to write a Windows batch file to read a directory, t hen feed each file name into the OO command line until there are no more files left.
Do, please

Re: Macro to print documents in the same directory

Posted: Mon Aug 14, 2017 4:00 pm
by RoryOF
With respect, you want it, you write it. I don't need to print files in such a way. I've already done some research for you and the process now should now be achievable using your existing skills gained from writing Excel macros,

Re: Macro to print documents in the same directory

Posted: Mon Aug 14, 2017 4:05 pm
by OOKapitan
Who can write me the example of the macro?

Re: Macro to print documents in the same directory

Posted: Mon Aug 14, 2017 5:30 pm
by Villeroy
Shell command to send all ODF documents in D:\Data\PrintDocs\ to the default printer:

Code: Select all

soffice.exe -p D:\Data\PrintDocs\*.od?
Same with explicit printer name:

Code: Select all

soffice.exe -pt PrinterName D:\Data\PrintDocs\*.od?

Re: Macro to print documents in the same directory

Posted: Tue Aug 15, 2017 9:21 am
by OOKapitan
Villeroy wrote:Shell command to send all ODF documents in D:\Data\PrintDocs\ to the default printer:

Code: Select all

soffice.exe -p D:\Data\PrintDocs\*.od?
Same with explicit printer name:

Code: Select all

soffice.exe -pt PrinterName D:\Data\PrintDocs\*.od?
all in the derrictory the file with macro is?
PrinterName in

Code: Select all

soffice.exe -pt PrinterName D:\Data\PrintDocs\*.od?
I need t change to the name of my printer?

Re: Macro to print documents in the same directory

Posted: Tue Aug 15, 2017 9:56 am
by robleyd
You run this from a command prompt - it is not an OpenOffice macro.

Code: Select all

soffice.exe -pt PrinterName D:\Data\PrintDocs\*.od?
Change PrinterName to your printer name only if you do not want to use the default printer.

Change D:\Data\PrintDocs\ to the directory where you keep the files you want to print. If you only want to print Calc spreadsheets, change *od? to *.ods then all the spreadsheets in the directory you have named will be printed.

Re: Macro to print documents in the same directory

Posted: Tue Aug 15, 2017 10:25 am
by OOKapitan
I understand and will test it. However what about an OpenOffice macro? I am just afraid to crash something on PC at work.

Re: Macro to print documents in the same directory

Posted: Tue Aug 15, 2017 10:40 am
by RoryOF
You are more likely to crash something using a macro.
Make a small test directory with two or three trivial files and try using that.

Re: Macro to print documents in the same directory

Posted: Tue Aug 15, 2017 10:47 am
by OOKapitan
RoryOF wrote:You are more likely to crash something using a macro.
Make a small test directory with two or three trivial files and try using that.
Thank you very much.

Re: Macro to print documents in the same directory

Posted: Tue Aug 15, 2017 10:49 am
by OOKapitan
robleyd wrote:You run this from a command prompt
May i create a bat file? Will it work? Or only from a command promt?

Re: Macro to print documents in the same directory

Posted: Tue Aug 15, 2017 10:54 am
by robleyd
Use a .bat file, command prompt or even a shortcut icon.

Re: Macro to print documents in the same directory

Posted: Tue Aug 15, 2017 10:55 am
by RoryOF
Start by using a command prompt and a small trial directory; when you have it working then is time to write a .bat file.

Re: Macro to print documents in the same directory

Posted: Tue Aug 15, 2017 4:56 pm
by OOKapitan
Nevertheless, is anyone able to write the macro?

Re: Macro to print documents in the same directory

Posted: Tue Aug 15, 2017 7:28 pm
by Zizi64

Re: Macro to print documents in the same directory

Posted: Wed Aug 16, 2017 10:07 am
by OOKapitan
Is anyone able to give me an I read a bit the links a post before, however I do something wrong when triing to adaptate the codes to my need.

Re: Macro to print documents in the same directory

Posted: Wed Aug 16, 2017 10:43 am
by Zizi64
Please upload your .ODF type file with the embedded macro code that you wrote.

Re: Macro to print documents in the same directory

Posted: Wed Aug 16, 2017 11:04 am
by OOKapitan
Here's what I got.
      But:
    1) it prints out from the directory c:\printpath, but I would like the macro to let me select a folder or to print out from the same folder the macro is in (to select the folder would be better);
    2) after each document asks whether it is printed or not, but I would like the macro after selecting a folder just to print all files in it.
      Also it would be better if the macro could print only files with the extension xls.
Help me please.

Re: Macro to print documents in the same directory

Posted: Wed Aug 16, 2017 12:10 pm
by Zizi64
1) it prints out from the directory c:\printpath, but I would like the macro to let me select a folder or to print out from the same folder the macro is in (to select the folder would be better);
The code snippet on the linked page contains: how you can select a specific directory:

Code: Select all

...
Dim sPath 
  sPath = getFolder("Please select a folder") & GetPathSeparator()
...



Function getFolder(sTitle AS String, optional sInitDir) AS String
   oPicker = CreateUnoService("com.sun.star.ui.dialogs.FolderPicker")
   oPicker.setTitle(sTitle)
   if not ismissing(sInitDir) then oPicker.setDisplayDirectory(sInitDir)
   if oPicker.execute() then getFolder = oPicker.getDirectory()
End Function

Re: Macro to print documents in the same directory

Posted: Wed Aug 23, 2017 4:42 pm
by OOKapitan
I tried. The macro allowes me to select the folder, but prints nothing. I forgot to say that the files must be opened visibly or they won't be printed.

Re: Macro to print documents in the same directory

Posted: Wed Aug 23, 2017 7:08 pm
by Zizi64
I tried. The macro allowes me to select the folder, but prints nothing. I forgot to say that the files must be opened visibly or they won't be printed.
Really, the usage of the filepicker is only the first part of the full macro what you needed. Then you must open (LoadFromURL...) the documents one by one (silently or visible) based on the picked path and the DIR strings as filenames, and then you will able to use the Print command of the API.

Re: Macro to print documents in the same directory

Posted: Thu Aug 24, 2017 9:10 am
by OOKapitan
Zizi64 wrote:
I tried. The macro allowes me to select the folder, but prints nothing. I forgot to say that the files must be opened visibly or they won't be printed.
Really, the usage of the filepicker is only the first part of the full macro what you needed. Then you must open (LoadFromURL...) the documents one by one (silently or visible) based on the picked path and the DIR strings as filenames, and then you will able to use the Print command of the API.
I do not no how to do this. Macro on the OpenOffice is a forest to me. I managed to write the macro I inserted two posts above by using parts of macro I found in the internet. In excel to write macro I in minimum just need to understand english. For macro in OpenOffice it doesn't work. Please help me to write full macro.

Re: Macro to print documents in the same directory

Posted: Thu Aug 24, 2017 11:59 am
by Zizi64
Please help me to write full macro.
Read and study Andrew Pitonyak's free macro books:
http://www.pitonyak.org/oo.php

The forum is not a free macro writing service.

Try to write a macro, upload the working example here, and we will (try to) fix your mistakes.

In excel to write macro I in minimum just need to understand english. For macro in OpenOffice it doesn't work.
Try the LibreOffice. It has a higher compatibility with the foreign fileformats and the MS VBA macros.